Browse files

adding sample app and slide deck for session at Android Developer Con…

…ference
  • Loading branch information...
1 parent a3d2dce commit d493bb267328199b4354a030fed4eaf99d69b4d4 @ppalavilli ppalavilli committed Mar 8, 2011
Showing with 1,807 additions and 0 deletions.
  1. +8 −0 AndroidDevCamp-March2011/PizzaApp-Complete/.classpath
  2. +33 −0 AndroidDevCamp-March2011/PizzaApp-Complete/.project
  3. +22 −0 AndroidDevCamp-March2011/PizzaApp-Complete/AndroidManifest.xml
  4. +13 −0 AndroidDevCamp-March2011/PizzaApp-Complete/default.properties
  5. +71 −0 AndroidDevCamp-March2011/PizzaApp-Complete/gen/com/paypal/MobilePayments/Pizza/R.java
  6. BIN AndroidDevCamp-March2011/PizzaApp-Complete/lib/PayPal_MPL.jar
  7. BIN AndroidDevCamp-March2011/PizzaApp-Complete/res/drawable/bg.png
  8. BIN AndroidDevCamp-March2011/PizzaApp-Complete/res/drawable/icon.png
  9. BIN AndroidDevCamp-March2011/PizzaApp-Complete/res/drawable/pizzaexpress.png
  10. +31 −0 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/customize.xml
  11. +37 −0 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/finalize.xml
  12. +35 −0 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/main.xml
  13. +62 −0 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/results.xml
  14. +73 −0 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/review.xml
  15. +5 −0 AndroidDevCamp-March2011/PizzaApp-Complete/res/values/strings.xml
  16. +643 −0 AndroidDevCamp-March2011/PizzaApp-Complete/src/com/paypal/MobilePayments/Pizza/PizzaMain.java
  17. +43 −0 AndroidDevCamp-March2011/PizzaApp-Complete/src/com/paypal/MobilePayments/Pizza/ResultDelegate.java
  18. +7 −0 AndroidDevCamp-March2011/PizzaApp/.classpath
  19. +33 −0 AndroidDevCamp-March2011/PizzaApp/.project
  20. +16 −0 AndroidDevCamp-March2011/PizzaApp/AndroidManifest.xml
  21. +13 −0 AndroidDevCamp-March2011/PizzaApp/default.properties
  22. +71 −0 AndroidDevCamp-March2011/PizzaApp/gen/com/paypal/MobilePayments/Pizza/R.java
  23. BIN AndroidDevCamp-March2011/PizzaApp/res/drawable/bg.png
  24. BIN AndroidDevCamp-March2011/PizzaApp/res/drawable/icon.png
  25. BIN AndroidDevCamp-March2011/PizzaApp/res/drawable/pizzaexpress.png
  26. +31 −0 AndroidDevCamp-March2011/PizzaApp/res/layout/customize.xml
  27. +37 −0 AndroidDevCamp-March2011/PizzaApp/res/layout/finalize.xml
  28. +35 −0 AndroidDevCamp-March2011/PizzaApp/res/layout/main.xml
  29. +62 −0 AndroidDevCamp-March2011/PizzaApp/res/layout/results.xml
  30. +73 −0 AndroidDevCamp-March2011/PizzaApp/res/layout/review.xml
  31. +5 −0 AndroidDevCamp-March2011/PizzaApp/res/values/strings.xml
  32. +348 −0 AndroidDevCamp-March2011/PizzaApp/src/com/paypal/MobilePayments/Pizza/PizzaMain.java
  33. BIN AndroidDevCamp-March2011/android_devcon-v3.pptx
View
8 AndroidDevCamp-March2011/PizzaApp-Complete/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="lib" path="lib/PayPal_MPL.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
33 AndroidDevCamp-March2011/PizzaApp-Complete/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>PizzaApp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
22 AndroidDevCamp-March2011/PizzaApp-Complete/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.paypal.MobilePayments.Pizza"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".PizzaMain"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity android:name="com.paypal.android.MEP.PayPalActivity"
+ android:theme="@android:style/Theme.Translucent.NoTitleBar"
+ android:configChanges="keyboardHidden|orientation"/>
+ </application>
+ <uses-sdk android:minSdkVersion="3" />
+ <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
+</manifest>
View
13 AndroidDevCamp-March2011/PizzaApp-Complete/default.properties
@@ -0,0 +1,13 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Indicates whether an apk should be generated for each density.
+split.density=false
+# Project target.
+target=android-8
View
71 AndroidDevCamp-March2011/PizzaApp-Complete/gen/com/paypal/MobilePayments/Pizza/R.java
@@ -0,0 +1,71 @@
+/* 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 com.paypal.MobilePayments.Pizza;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int bg=0x7f020000;
+ public static final int icon=0x7f020001;
+ public static final int pizzaexpress=0x7f020002;
+ }
+ public static final class id {
+ public static final int Button03=0x7f050004;
+ public static final int Buy=0x7f05000c;
+ public static final int BuyMore=0x7f050012;
+ public static final int Continue=0x7f050005;
+ public static final int DeliveryFee=0x7f05001a;
+ public static final int DeliveryFeePrice=0x7f050024;
+ public static final int Done=0x7f050013;
+ public static final int ExtraCheese=0x7f050015;
+ public static final int ExtraCheesePrice=0x7f05001f;
+ public static final int ImageView01=0x7f05000a;
+ public static final int ImageView02=0x7f05000d;
+ public static final int Method=0x7f05001d;
+ public static final int MethodType=0x7f050027;
+ public static final int Mushrooms=0x7f050017;
+ public static final int MushroomsPrice=0x7f050021;
+ public static final int NumberOfPizzas=0x7f050014;
+ public static final int Onions=0x7f050018;
+ public static final int OnionsPrice=0x7f050022;
+ public static final int Pepperoni=0x7f050016;
+ public static final int PepperoniPrice=0x7f050020;
+ public static final int Price=0x7f05001e;
+ public static final int RelativeLayout01=0x7f050000;
+ public static final int RelativeLayout03=0x7f050006;
+ public static final int ResultsText1=0x7f05000f;
+ public static final int ResultsText2=0x7f050010;
+ public static final int ResultsText3=0x7f050011;
+ public static final int ResultsTitle=0x7f05000e;
+ public static final int ReviewOrder=0x7f050009;
+ public static final int Spinner01=0x7f050002;
+ public static final int Spinner02=0x7f050007;
+ public static final int Spinner03=0x7f050008;
+ public static final int Subtotal=0x7f050019;
+ public static final int SubtotalPrice=0x7f050023;
+ public static final int Tax=0x7f05001b;
+ public static final int TaxPrice=0x7f050025;
+ public static final int TextView01=0x7f050001;
+ public static final int TextView02=0x7f050003;
+ public static final int Total=0x7f05001c;
+ public static final int TotalPrice=0x7f050026;
+ public static final int buildNumber=0x7f05000b;
+ }
+ public static final class layout {
+ public static final int customize=0x7f030000;
+ public static final int finalize=0x7f030001;
+ public static final int main=0x7f030002;
+ public static final int results=0x7f030003;
+ public static final int review=0x7f030004;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040001;
+ public static final int hello=0x7f040000;
+ }
+}
View
BIN AndroidDevCamp-March2011/PizzaApp-Complete/lib/PayPal_MPL.jar
Binary file not shown.
View
BIN AndroidDevCamp-March2011/PizzaApp-Complete/res/drawable/bg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN AndroidDevCamp-March2011/PizzaApp-Complete/res/drawable/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN AndroidDevCamp-March2011/PizzaApp-Complete/res/drawable/pizzaexpress.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
31 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/customize.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent"
+android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
+android:background="@drawable/bg">
+
+
+
+<TextView android:layout_width="wrap_content" android:id="@+id/TextView01"
+android:layout_centerHorizontal="true" android:layout_marginTop="20dip"
+android:layout_height="wrap_content"
+android:layout_alignParentTop="true"
+android:text="Select a size"></TextView>
+
+<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content"
+android:layout_centerHorizontal="true"
+android:layout_below="@+id/TextView01"
+android:layout_height="wrap_content"></Spinner>
+
+
+<TextView android:layout_below="@+id/Spinner01" android:layout_width="wrap_content" android:id="@+id/TextView02" android:layout_centerHorizontal="true" android:layout_height="wrap_content" android:text="Toppings ($2 each)"></TextView>
+
+<Button android:layout_below="@+id/TextView02" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_height="wrap_content" android:text="Choose your toppings" android:id="@+id/Button03"></Button>
+
+<Button android:layout_width="wrap_content"
+android:layout_height="wrap_content" android:text="Continue" android:paddingTop="10dip"
+android:layout_alignParentBottom="true"
+android:layout_centerHorizontal="true"
+android:layout_marginBottom="10dip" android:id="@+id/Continue"></Button>
+
+</RelativeLayout>
View
37 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/finalize.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<RelativeLayout android:id="@+id/RelativeLayout03" android:layout_width="fill_parent"
+android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
+android:background="@drawable/bg">
+
+
+
+<TextView android:layout_width="wrap_content" android:id="@+id/TextView01"
+android:layout_centerHorizontal="true" android:layout_height="wrap_content"
+android:layout_marginTop="20dip"
+android:layout_alignParentTop="true"
+android:text="Select the number of pizzas"></TextView>
+
+<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content"
+android:layout_centerHorizontal="true"
+android:layout_below="@+id/TextView01"
+android:layout_height="wrap_content"></Spinner>
+
+
+<TextView android:layout_below="@+id/Spinner02" android:layout_width="wrap_content"
+ android:id="@+id/TextView02" android:layout_centerHorizontal="true"
+ android:layout_height="wrap_content" android:text="Choose delivery/pickup"></TextView>
+
+ <Spinner android:id="@+id/Spinner03" android:layout_width="wrap_content"
+android:layout_centerHorizontal="true"
+android:layout_below="@+id/TextView02"
+android:layout_height="wrap_content"></Spinner>
+
+
+<Button android:layout_width="wrap_content"
+android:layout_height="wrap_content" android:text="Review Order" android:paddingTop="10dip"
+android:layout_alignParentBottom="true"
+android:layout_centerHorizontal="true"
+android:layout_marginBottom="10dip" android:id="@+id/ReviewOrder"></Button>
+
+</RelativeLayout>
View
35 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/main.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@drawable/bg">
+
+<ImageView android:id="@+id/ImageView01"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/pizzaexpress"
+ android:layout_alignParentTop="true"
+ android:layout_marginTop="20dip"
+ android:layout_centerHorizontal="true"
+ android:paddingBottom="10dip"></ImageView>
+
+<TextView android:layout_alignParentBottom="true"
+ android:layout_marginBottom="10dip"
+ android:layout_height="wrap_content"
+ android:id="@+id/buildNumber"
+ android:layout_width="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:text="10.8.6.4682"></TextView>
+
+<Button android:layout_width="wrap_content"
+ android:layout_above="@+id/buildNumber"
+ android:layout_height="wrap_content"
+ android:text="Buy a pizza!"
+ android:paddingTop="10dip"
+ android:gravity="center_vertical"
+ android:layout_centerHorizontal="true"
+ android:paddingBottom="10dip"
+ android:id="@+id/Buy"></Button>
+
+</RelativeLayout>
View
62 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/results.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:fillViewport="true">
+ <LinearLayout android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center_horizontal"
+ android:background="@drawable/bg">
+ <ImageView android:id="@+id/ImageView02"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="20dip"
+ android:background="@drawable/pizzaexpress"
+ android:paddingBottom="10dip"/>
+ <TextView android:id="@+id/ResultsTitle"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_marginTop="20dip"
+ android:text="Default"
+ android:textSize="24dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <TextView android:id="@+id/ResultsText1"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text=""
+ android:textSize="16dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <TextView android:id="@+id/ResultsText2"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text=""
+ android:textSize="16dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <TextView android:id="@+id/ResultsText3"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="Default"
+ android:textSize="12dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <LinearLayout android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center_horizontal"
+ android:paddingTop="20dip">
+ <Button android:id="@+id/BuyMore"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Buy More!"/>
+ <Button android:id="@+id/Done"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="I'm Done!"/>
+ </LinearLayout>
+ </LinearLayout>
+</ScrollView>
View
73 AndroidDevCamp-March2011/PizzaApp-Complete/res/layout/review.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent"
+android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
+android:background="@drawable/bg"
+android:paddingLeft="20dip"
+android:paddingRight="20dip"
+android:gravity="top">
+
+<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
+android:layout_marginTop="20dip"
+android:textSize="16dip"
+android:text="Number of Pizzas" android:id="@+id/NumberOfPizzas"></TextView>
+
+
+<TextView android:layout_height="wrap_content" android:layout_below="@+id/NumberOfPizzas" android:textSize="16dip"
+android:layout_width="wrap_content" android:text="Extra Cheese" android:id="@+id/ExtraCheese"></TextView>
+<TextView android:layout_height="wrap_content" android:textSize="16dip"
+android:layout_below="@+id/ExtraCheese"
+android:layout_width="wrap_content" android:text="Pepperoni" android:id="@+id/Pepperoni"></TextView>
+<TextView android:layout_height="wrap_content" android:textSize="16dip"
+android:layout_below="@+id/Pepperoni" android:layout_width="wrap_content" android:text="Mushrooms" android:id="@+id/Mushrooms"></TextView><TextView android:layout_height="wrap_content"
+android:textSize="16dip" android:layout_below="@+id/Mushrooms"
+android:layout_width="wrap_content" android:text="Onions"
+android:id="@+id/Onions"></TextView>
+<TextView android:layout_height="wrap_content"
+android:textSize="16dip" android:layout_below="@+id/Onions"
+android:layout_width="wrap_content" android:text="Subtotal"
+android:id="@+id/Subtotal"></TextView>
+<TextView android:layout_height="wrap_content"
+android:textSize="16dip" android:layout_below="@+id/Subtotal"
+ android:layout_width="wrap_content" android:text="Delivery Fee"
+ android:id="@+id/DeliveryFee"></TextView>
+ <TextView android:layout_below="@+id/DeliveryFee"
+ android:textSize="16dip" android:layout_height="wrap_content"
+ android:layout_width="wrap_content" android:text="Tax"
+ android:id="@+id/Tax"></TextView>
+ <TextView android:layout_below="@+id/Tax"
+ android:layout_height="wrap_content"
+ android:textSize="16dip" android:layout_width="wrap_content"
+ android:text="Total" android:id="@+id/Total"></TextView>
+ <TextView android:layout_below="@+id/Total" android:textSize="16dip"
+ android:layout_height="wrap_content" android:layout_width="wrap_content"
+ android:text="Method:" android:id="@+id/Method"></TextView>
+ <TextView android:layout_height="wrap_content" android:textSize="16dip"
+ android:layout_width="wrap_content"
+
+android:layout_toRightOf="@+id/NumberOfPizzas" android:layout_marginTop="20dip"
+ android:id="@+id/Price" android:text="Price"
+android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content"
+android:layout_below="@+id/Price"
+android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas"
+android:id="@+id/ExtraCheesePrice"
+android:textSize="16dip" android:text="$2.00" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/ExtraCheesePrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$2.00" android:id="@+id/PepperoniPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/PepperoniPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$2.00" android:id="@+id/MushroomsPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/MushroomsPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$2.00" android:paddingLeft="10dip" android:id="@+id/OnionsPrice"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/OnionsPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$25.99" android:id="@+id/SubtotalPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/SubtotalPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:id="@+id/DeliveryFeePrice" android:paddingLeft="10dip" android:text="$2.00"></TextView>
+
+
+<TextView android:layout_toRightOf="@+id/NumberOfPizzas" android:textSize="16dip" android:layout_below="@+id/DeliveryFeePrice" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="$1.80" android:id="@+id/TaxPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_toRightOf="@+id/NumberOfPizzas" android:textSize="16dip" android:layout_below="@+id/TaxPrice" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="$33.54" android:id="@+id/TotalPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_toRightOf="@+id/NumberOfPizzas" android:textSize="16dip" android:layout_below="@+id/TotalPrice" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/MethodType" android:paddingLeft="10dip" android:text="Delivery"></TextView>
+</RelativeLayout>
View
5 AndroidDevCamp-March2011/PizzaApp-Complete/res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World, PizzaMain!</string>
+ <string name="app_name">PizzaApp</string>
+</resources>
View
643 ...oidDevCamp-March2011/PizzaApp-Complete/src/com/paypal/MobilePayments/Pizza/PizzaMain.java
@@ -0,0 +1,643 @@
+package com.paypal.MobilePayments.Pizza;
+
+import java.math.BigDecimal;
+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.app.ProgressDialog;
+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.Gravity;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.RelativeLayout;
+import android.widget.RelativeLayout.LayoutParams;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import com.paypal.android.MEP.CheckoutButton;
+import com.paypal.android.MEP.PayPal;
+import com.paypal.android.MEP.PayPalActivity;
+import com.paypal.android.MEP.PayPalInvoiceData;
+import com.paypal.android.MEP.PayPalPayment;
+
+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
+ 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
+ private double _theSubtotal;
+ private double _taxAmount;
+ private String _pizzaDescription;
+
+ // 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)
+ private NumberFormat _df;
+
+ /*
+ * PayPal library related fields
+ */
+ private CheckoutButton launchPayPalButton;
+ final static public int PAYPAL_BUTTON_ID = 10001;
+ private static final int REQUEST_PAYPAL_CHECKOUT = 2;
+ // Keeps a reference to the progress dialog
+ private ProgressDialog _progressDialog;
+ private boolean _paypalLibraryInit = false;
+ private boolean _progressDialogRunning = false;
+
+
+ // 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);
+ // Initialize the library.
+ if (this.isOnline()) {
+ Thread libraryInitializationThread = new Thread() {
+ public void run() {
+ initLibrary();
+ }
+ };
+
+ libraryInitializationThread.start();
+ }
+
+ 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);
+ 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
+ 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");
+ 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"));
+ 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));
+
+ // insert the PayPal button
+ // Check 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
+ if (_paypalLibraryInit) {
+ showPayPalButton();
+ } else {
+ // Display a progress dialog to the user and start checking for when
+ // the initialization is completed
+ _progressDialog = new ProgressDialog(this);
+ _progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ _progressDialog.setMessage("Loading PayPal Payment Library");
+ _progressDialog.setCancelable(false);
+ _progressDialog.show();
+ _progressDialogRunning = true;
+ Thread newThread = new Thread(checkforPayPalInitRunnable);
+ newThread.start();
+ }
+
+ }
+
+
+
+ // PayPal Activity Results. This handles all the responses from the PayPal
+ // Payments Library
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+
+ if (requestCode == REQUEST_PAYPAL_CHECKOUT) {
+ PayPalActivityResult(requestCode, resultCode, intent);
+ } else {
+ 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
+ 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" };
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Choose your toppings");
+ 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();
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.setOnDismissListener(this);
+ alert.show();
+ } else if (arg0 == (Button) findViewById(R.id.Continue)) {
+ loadFinalizePage();
+ } else if (arg0 == (Button) findViewById(R.id.ReviewOrder)) {
+ loadReviewPage();
+ } else if (arg0 == (Button) findViewById(R.id.BuyMore)) {
+ loadMainPage();
+ } else if (arg0 == (Button) findViewById(R.id.Done)) {
+ finish();
+ } else if (arg0 == (CheckoutButton) findViewById(PAYPAL_BUTTON_ID)) {
+ PayPalButtonClick(arg0);
+ }
+
+ }
+
+ @Override
+ public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
+ long arg3) {
+ // Lets us track the spinner view
+ if (arg0 == findViewById(R.id.Spinner01)) {
+ _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
+ public void onNothingSelected(AdapterView<?> arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void onClick(DialogInterface arg0, int arg1, boolean arg2) {
+ // this is the topping selector
+ if (arg1 == 0) {
+ _cheese = arg2;
+ } else if (arg1 == 1) {
+ _pepperoni = arg2;
+ } else if (arg1 == 2) {
+ _mushrooms = arg2;
+ } else {
+ _onions = arg2;
+ }
+ }
+
+ 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.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
+ 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("");
+ }
+
+ @Override
+ public void onDismiss(DialogInterface arg0) {
+ findViewById(R.id.Continue).setVisibility(View.VISIBLE);
+ }
+
+
+ /**********************************
+ * PayPal library related methods
+ **********************************/
+
+ // This lets us show the PayPal Button after the library has been
+ // initialized
+ final Runnable showPayPalButtonRunnable = new Runnable() {
+ public void run() {
+ showPayPalButton();
+ }
+ };
+
+ // This lets us run a loop to check the status of the PayPal Library init
+ final Runnable checkforPayPalInitRunnable = new Runnable() {
+ public void run() {
+ checkForPayPalLibraryInit();
+ }
+ };
+
+ // This method is called if the Review page is being loaded but the PayPal
+ // Library is not
+ // initialized yet.
+ private void checkForPayPalLibraryInit() {
+ // Loop as long as the library is not initialized
+ while (_paypalLibraryInit == false) {
+ try {
+ // wait 1/2 a second then check again
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ // Show an error to the user
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage("Error initializing PayPal Library")
+ .setCancelable(false)
+ .setPositiveButton("OK",
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int id) {
+ // Could do anything here to handle the
+ // error
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
+ }
+ }
+ // If we got here, it means the library is initialized.
+ // So, add the "Pay with PayPal" button to the screen
+ runOnUiThread(showPayPalButtonRunnable);
+ }
+
+ /**
+ * The initLibrary function takes care of all the basic Library
+ * initialization.
+ *
+ * @return The return will be true if the initialization was successful and
+ * false if
+ */
+ public void initLibrary() {
+ PayPal pp = PayPal.getInstance();
+ // If the library is already initialized, then we don't need to
+ // initialize it again.
+ if (pp == null) {
+ // 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);
+
+ // -- These are required settings.
+ pp.setLanguage("en_US"); // Sets the language for the library.
+ // --
+
+ // -- These are a few of the optional settings.
+ // Sets the fees payer. If there are fees for the transaction, this
+ // person will pay for them. Possible values are FEEPAYER_SENDER,
+ // FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and
+ // FEEPAYER_SECONDARYONLY.
+ pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
+ // Set to true if the transaction will require shipping.
+ pp.setShippingEnabled(true);
+ // Dynamic Amount Calculation allows you to set tax and shipping
+ // amounts based on the user's shipping address. Shipping must be
+ // enabled for Dynamic Amount Calculation. This also requires you to
+ // create a class that implements PaymentAdjuster and Serializable.
+ pp.setDynamicAmountCalculationEnabled(false);
+ // --
+ _paypalLibraryInit = true;
+ }
+ }
+ private void showPayPalButton() {
+ removePayPalButton();
+ // Back in the UI thread -- show the "Pay with PayPal" button
+ // Generate the PayPal Checkout button and save it for later use
+ PayPal pp = PayPal.getInstance();
+ launchPayPalButton = pp.getCheckoutButton(this, PayPal.BUTTON_278x43,
+ CheckoutButton.TEXT_PAY);
+ // You'll need to have an OnClickListener for the CheckoutButton.
+ launchPayPalButton.setOnClickListener(this);
+ // add it to the layout
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
+ LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
+ params.bottomMargin = 10;
+
+ launchPayPalButton.setLayoutParams(params);
+ launchPayPalButton.setId(PAYPAL_BUTTON_ID);
+ ((RelativeLayout) findViewById(R.id.RelativeLayout01))
+ .addView(launchPayPalButton);
+ ((RelativeLayout) findViewById(R.id.RelativeLayout01))
+ .setGravity(Gravity.CENTER_HORIZONTAL);
+ if (_progressDialogRunning) {
+ _progressDialog.dismiss();
+ _progressDialogRunning = false;
+ }
+ }
+
+ private void removePayPalButton() {
+ // Avoid an exception for setting a parent more than once
+ if (launchPayPalButton != null) {
+ ((RelativeLayout) findViewById(R.id.RelativeLayout01))
+ .removeView(launchPayPalButton);
+ }
+ }
+
+
+ public void PayPalButtonClick(View arg0) {
+
+ // Create a basic PayPalPayment.
+ PayPalPayment payment = new PayPalPayment();
+ // Sets the currency type for this payment.
+ payment.setCurrencyType("USD");
+ // Sets the recipient for the payment. This can also be a phone
+ // number.
+ payment.setRecipient("ppalav_1285013097_biz@yahoo.com");
+ // Sets the amount of the payment, not including tax and shipping
+ // amounts.
+ payment.setSubtotal(new BigDecimal(_theSubtotal));
+ // Sets the payment type. This can be PAYMENT_TYPE_GOODS,
+ // PAYMENT_TYPE_SERVICE, PAYMENT_TYPE_PERSONAL, or
+ // PAYMENT_TYPE_NONE.
+ payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
+
+ // PayPalInvoiceData can contain tax and shipping amounts. It also
+ // contains an ArrayList of PayPalInvoiceItem which can
+ // be filled out. These are not required for any transaction.
+ PayPalInvoiceData invoice = new PayPalInvoiceData();
+ // Sets the tax amount.
+ invoice.setTax(new BigDecimal(_taxAmount));
+ // 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);
+ }
+
+ // Sets the PayPalPayment invoice data.
+ payment.setInvoiceData(invoice);
+ // Sets the merchant name. This is the name of your Application or
+ // Company.
+ payment.setMerchantName("Pizza Express");
+ // Sets the description of the payment.
+ payment.setDescription(_pizzaDescription);
+
+ // Use checkout to create our Intent.
+ Intent checkoutIntent = PayPal.getInstance()
+ .checkout(payment, this /*, new ResultDelegate()*/);
+ // Use the android's startActivityForResult() and pass in our
+ // Intent.
+ // This will start the library.
+ startActivityForResult(checkoutIntent, REQUEST_PAYPAL_CHECKOUT);
+ }
+ // PayPal Activity Results. This handles all the responses from the PayPal
+ // Payments Library
+ public void PayPalActivityResult(int requestCode, int resultCode, Intent intent) {
+ switch (resultCode) {
+ case Activity.RESULT_OK:
+ // The payment succeeded
+ String payKey = intent
+ .getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
+ this.paymentSucceeded(payKey);
+ break;
+ case Activity.RESULT_CANCELED:
+ // The payment was canceled
+ this.paymentCanceled();
+ break;
+ case PayPalActivity.RESULT_FAILURE:
+ // The payment failed -- we get the error from the
+ // EXTRA_ERROR_ID and EXTRA_ERROR_MESSAGE
+ String errorID = intent
+ .getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
+ String errorMessage = intent
+ .getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
+ this.paymentFailed(errorID, errorMessage);
+ }
+ }
+}
View
43 ...vCamp-March2011/PizzaApp-Complete/src/com/paypal/MobilePayments/Pizza/ResultDelegate.java
@@ -0,0 +1,43 @@
+package com.paypal.MobilePayments.Pizza;
+
+import java.io.Serializable;
+
+import com.paypal.android.MEP.PayPalResultDelegate;
+
+public class ResultDelegate implements PayPalResultDelegate, Serializable {
+
+ private static final long serialVersionUID = 10001L;
+
+ /**
+ * Notification that the payment has been completed successfully.
+ *
+ * @param payKey the pay key for the payment
+ * @param paymentStatus the status of the transaction
+ */
+ public void onPaymentSucceeded(String payKey, String paymentStatus) {
+ // nothing to do for now
+ }
+
+ /**
+ * Notification that the payment has failed.
+ *
+ * @param paymentStatus the status of the transaction
+ * @param correlationID the correlationID for the transaction failure
+ * @param payKey the pay key for the payment
+ * @param errorID the ID of the error that occurred
+ * @param errorMessage the error message for the error that occurred
+ */
+ public void onPaymentFailed(String paymentStatus, String correlationID,
+ String payKey, String errorID, String errorMessage) {
+ // nothing to do for now
+ }
+
+ /**
+ * Notification that the payment was canceled.
+ *
+ * @param paymentStatus the status of the transaction
+ */
+ public void onPaymentCanceled(String paymentStatus) {
+ // nothing to do for now
+ }
+}
View
7 AndroidDevCamp-March2011/PizzaApp/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
33 AndroidDevCamp-March2011/PizzaApp/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>PizzaApp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
16 AndroidDevCamp-March2011/PizzaApp/AndroidManifest.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.paypal.MobilePayments.Pizza"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".PizzaMain"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+ <uses-sdk android:minSdkVersion="3" />
+</manifest>
View
13 AndroidDevCamp-March2011/PizzaApp/default.properties
@@ -0,0 +1,13 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Indicates whether an apk should be generated for each density.
+split.density=false
+# Project target.
+target=android-8
View
71 AndroidDevCamp-March2011/PizzaApp/gen/com/paypal/MobilePayments/Pizza/R.java
@@ -0,0 +1,71 @@
+/* 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 com.paypal.MobilePayments.Pizza;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int bg=0x7f020000;
+ public static final int icon=0x7f020001;
+ public static final int pizzaexpress=0x7f020002;
+ }
+ public static final class id {
+ public static final int Button03=0x7f050004;
+ public static final int Buy=0x7f05000c;
+ public static final int BuyMore=0x7f050012;
+ public static final int Continue=0x7f050005;
+ public static final int DeliveryFee=0x7f05001a;
+ public static final int DeliveryFeePrice=0x7f050024;
+ public static final int Done=0x7f050013;
+ public static final int ExtraCheese=0x7f050015;
+ public static final int ExtraCheesePrice=0x7f05001f;
+ public static final int ImageView01=0x7f05000a;
+ public static final int ImageView02=0x7f05000d;
+ public static final int Method=0x7f05001d;
+ public static final int MethodType=0x7f050027;
+ public static final int Mushrooms=0x7f050017;
+ public static final int MushroomsPrice=0x7f050021;
+ public static final int NumberOfPizzas=0x7f050014;
+ public static final int Onions=0x7f050018;
+ public static final int OnionsPrice=0x7f050022;
+ public static final int Pepperoni=0x7f050016;
+ public static final int PepperoniPrice=0x7f050020;
+ public static final int Price=0x7f05001e;
+ public static final int RelativeLayout01=0x7f050000;
+ public static final int RelativeLayout03=0x7f050006;
+ public static final int ResultsText1=0x7f05000f;
+ public static final int ResultsText2=0x7f050010;
+ public static final int ResultsText3=0x7f050011;
+ public static final int ResultsTitle=0x7f05000e;
+ public static final int ReviewOrder=0x7f050009;
+ public static final int Spinner01=0x7f050002;
+ public static final int Spinner02=0x7f050007;
+ public static final int Spinner03=0x7f050008;
+ public static final int Subtotal=0x7f050019;
+ public static final int SubtotalPrice=0x7f050023;
+ public static final int Tax=0x7f05001b;
+ public static final int TaxPrice=0x7f050025;
+ public static final int TextView01=0x7f050001;
+ public static final int TextView02=0x7f050003;
+ public static final int Total=0x7f05001c;
+ public static final int TotalPrice=0x7f050026;
+ public static final int buildNumber=0x7f05000b;
+ }
+ public static final class layout {
+ public static final int customize=0x7f030000;
+ public static final int finalize=0x7f030001;
+ public static final int main=0x7f030002;
+ public static final int results=0x7f030003;
+ public static final int review=0x7f030004;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040001;
+ public static final int hello=0x7f040000;
+ }
+}
View
BIN AndroidDevCamp-March2011/PizzaApp/res/drawable/bg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN AndroidDevCamp-March2011/PizzaApp/res/drawable/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN AndroidDevCamp-March2011/PizzaApp/res/drawable/pizzaexpress.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
31 AndroidDevCamp-March2011/PizzaApp/res/layout/customize.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent"
+android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
+android:background="@drawable/bg">
+
+
+
+<TextView android:layout_width="wrap_content" android:id="@+id/TextView01"
+android:layout_centerHorizontal="true" android:layout_marginTop="20dip"
+android:layout_height="wrap_content"
+android:layout_alignParentTop="true"
+android:text="Select a size"></TextView>
+
+<Spinner android:id="@+id/Spinner01" android:layout_width="wrap_content"
+android:layout_centerHorizontal="true"
+android:layout_below="@+id/TextView01"
+android:layout_height="wrap_content"></Spinner>
+
+
+<TextView android:layout_below="@+id/Spinner01" android:layout_width="wrap_content" android:id="@+id/TextView02" android:layout_centerHorizontal="true" android:layout_height="wrap_content" android:text="Toppings ($2 each)"></TextView>
+
+<Button android:layout_below="@+id/TextView02" android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_height="wrap_content" android:text="Choose your toppings" android:id="@+id/Button03"></Button>
+
+<Button android:layout_width="wrap_content"
+android:layout_height="wrap_content" android:text="Continue" android:paddingTop="10dip"
+android:layout_alignParentBottom="true"
+android:layout_centerHorizontal="true"
+android:layout_marginBottom="10dip" android:id="@+id/Continue"></Button>
+
+</RelativeLayout>
View
37 AndroidDevCamp-March2011/PizzaApp/res/layout/finalize.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<RelativeLayout android:id="@+id/RelativeLayout03" android:layout_width="fill_parent"
+android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
+android:background="@drawable/bg">
+
+
+
+<TextView android:layout_width="wrap_content" android:id="@+id/TextView01"
+android:layout_centerHorizontal="true" android:layout_height="wrap_content"
+android:layout_marginTop="20dip"
+android:layout_alignParentTop="true"
+android:text="Select the number of pizzas"></TextView>
+
+<Spinner android:id="@+id/Spinner02" android:layout_width="wrap_content"
+android:layout_centerHorizontal="true"
+android:layout_below="@+id/TextView01"
+android:layout_height="wrap_content"></Spinner>
+
+
+<TextView android:layout_below="@+id/Spinner02" android:layout_width="wrap_content"
+ android:id="@+id/TextView02" android:layout_centerHorizontal="true"
+ android:layout_height="wrap_content" android:text="Choose delivery/pickup"></TextView>
+
+ <Spinner android:id="@+id/Spinner03" android:layout_width="wrap_content"
+android:layout_centerHorizontal="true"
+android:layout_below="@+id/TextView02"
+android:layout_height="wrap_content"></Spinner>
+
+
+<Button android:layout_width="wrap_content"
+android:layout_height="wrap_content" android:text="Review Order" android:paddingTop="10dip"
+android:layout_alignParentBottom="true"
+android:layout_centerHorizontal="true"
+android:layout_marginBottom="10dip" android:id="@+id/ReviewOrder"></Button>
+
+</RelativeLayout>
View
35 AndroidDevCamp-March2011/PizzaApp/res/layout/main.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@drawable/bg">
+
+<ImageView android:id="@+id/ImageView01"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/pizzaexpress"
+ android:layout_alignParentTop="true"
+ android:layout_marginTop="20dip"
+ android:layout_centerHorizontal="true"
+ android:paddingBottom="10dip"></ImageView>
+
+<TextView android:layout_alignParentBottom="true"
+ android:layout_marginBottom="10dip"
+ android:layout_height="wrap_content"
+ android:id="@+id/buildNumber"
+ android:layout_width="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:text="10.8.6.4682"></TextView>
+
+<Button android:layout_width="wrap_content"
+ android:layout_above="@+id/buildNumber"
+ android:layout_height="wrap_content"
+ android:text="Buy a pizza!"
+ android:paddingTop="10dip"
+ android:gravity="center_vertical"
+ android:layout_centerHorizontal="true"
+ android:paddingBottom="10dip"
+ android:id="@+id/Buy"></Button>
+
+</RelativeLayout>
View
62 AndroidDevCamp-March2011/PizzaApp/res/layout/results.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:fillViewport="true">
+ <LinearLayout android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center_horizontal"
+ android:background="@drawable/bg">
+ <ImageView android:id="@+id/ImageView02"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="20dip"
+ android:background="@drawable/pizzaexpress"
+ android:paddingBottom="10dip"/>
+ <TextView android:id="@+id/ResultsTitle"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_marginTop="20dip"
+ android:text="Default"
+ android:textSize="24dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <TextView android:id="@+id/ResultsText1"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text=""
+ android:textSize="16dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <TextView android:id="@+id/ResultsText2"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text=""
+ android:textSize="16dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <TextView android:id="@+id/ResultsText3"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="Default"
+ android:textSize="12dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"/>
+ <LinearLayout android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center_horizontal"
+ android:paddingTop="20dip">
+ <Button android:id="@+id/BuyMore"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Buy More!"/>
+ <Button android:id="@+id/Done"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="I'm Done!"/>
+ </LinearLayout>
+ </LinearLayout>
+</ScrollView>
View
73 AndroidDevCamp-March2011/PizzaApp/res/layout/review.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent"
+android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
+android:background="@drawable/bg"
+android:paddingLeft="20dip"
+android:paddingRight="20dip"
+android:gravity="top">
+
+<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
+android:layout_marginTop="20dip"
+android:textSize="16dip"
+android:text="Number of Pizzas" android:id="@+id/NumberOfPizzas"></TextView>
+
+
+<TextView android:layout_height="wrap_content" android:layout_below="@+id/NumberOfPizzas" android:textSize="16dip"
+android:layout_width="wrap_content" android:text="Extra Cheese" android:id="@+id/ExtraCheese"></TextView>
+<TextView android:layout_height="wrap_content" android:textSize="16dip"
+android:layout_below="@+id/ExtraCheese"
+android:layout_width="wrap_content" android:text="Pepperoni" android:id="@+id/Pepperoni"></TextView>
+<TextView android:layout_height="wrap_content" android:textSize="16dip"
+android:layout_below="@+id/Pepperoni" android:layout_width="wrap_content" android:text="Mushrooms" android:id="@+id/Mushrooms"></TextView><TextView android:layout_height="wrap_content"
+android:textSize="16dip" android:layout_below="@+id/Mushrooms"
+android:layout_width="wrap_content" android:text="Onions"
+android:id="@+id/Onions"></TextView>
+<TextView android:layout_height="wrap_content"
+android:textSize="16dip" android:layout_below="@+id/Onions"
+android:layout_width="wrap_content" android:text="Subtotal"
+android:id="@+id/Subtotal"></TextView>
+<TextView android:layout_height="wrap_content"
+android:textSize="16dip" android:layout_below="@+id/Subtotal"
+ android:layout_width="wrap_content" android:text="Delivery Fee"
+ android:id="@+id/DeliveryFee"></TextView>
+ <TextView android:layout_below="@+id/DeliveryFee"
+ android:textSize="16dip" android:layout_height="wrap_content"
+ android:layout_width="wrap_content" android:text="Tax"
+ android:id="@+id/Tax"></TextView>
+ <TextView android:layout_below="@+id/Tax"
+ android:layout_height="wrap_content"
+ android:textSize="16dip" android:layout_width="wrap_content"
+ android:text="Total" android:id="@+id/Total"></TextView>
+ <TextView android:layout_below="@+id/Total" android:textSize="16dip"
+ android:layout_height="wrap_content" android:layout_width="wrap_content"
+ android:text="Method:" android:id="@+id/Method"></TextView>
+ <TextView android:layout_height="wrap_content" android:textSize="16dip"
+ android:layout_width="wrap_content"
+
+android:layout_toRightOf="@+id/NumberOfPizzas" android:layout_marginTop="20dip"
+ android:id="@+id/Price" android:text="Price"
+android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content"
+android:layout_below="@+id/Price"
+android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas"
+android:id="@+id/ExtraCheesePrice"
+android:textSize="16dip" android:text="$2.00" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/ExtraCheesePrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$2.00" android:id="@+id/PepperoniPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/PepperoniPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$2.00" android:id="@+id/MushroomsPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/MushroomsPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$2.00" android:paddingLeft="10dip" android:id="@+id/OnionsPrice"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/OnionsPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:text="$25.99" android:id="@+id/SubtotalPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_height="wrap_content" android:textSize="16dip" android:layout_below="@+id/SubtotalPrice" android:layout_width="wrap_content" android:layout_toRightOf="@+id/NumberOfPizzas" android:id="@+id/DeliveryFeePrice" android:paddingLeft="10dip" android:text="$2.00"></TextView>
+
+
+<TextView android:layout_toRightOf="@+id/NumberOfPizzas" android:textSize="16dip" android:layout_below="@+id/DeliveryFeePrice" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="$1.80" android:id="@+id/TaxPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_toRightOf="@+id/NumberOfPizzas" android:textSize="16dip" android:layout_below="@+id/TaxPrice" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="$33.54" android:id="@+id/TotalPrice" android:paddingLeft="10dip"></TextView>
+
+<TextView android:layout_toRightOf="@+id/NumberOfPizzas" android:textSize="16dip" android:layout_below="@+id/TotalPrice" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/MethodType" android:paddingLeft="10dip" android:text="Delivery"></TextView>
+</RelativeLayout>
View
5 AndroidDevCamp-March2011/PizzaApp/res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World, PizzaMain!</string>
+ <string name="app_name">PizzaApp</string>
+</resources>
View
348 AndroidDevCamp-March2011/PizzaApp/src/com/paypal/MobilePayments/Pizza/PizzaMain.java
@@ -0,0 +1,348 @@
+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.DialogInterface;
+import android.content.DialogInterface.OnDismissListener;
+import android.content.DialogInterface.OnMultiChoiceClickListener;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+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. */
+
+ //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
+ private double _theSubtotal;
+ private double _taxAmount;
+ private String _pizzaDescription;
+
+ //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)
+ private NumberFormat _df;
+
+
+
+ @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);
+ 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
+ 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");
+ 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"));
+ 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
+ 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
+ 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"};
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Choose your toppings");
+ 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();
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.setOnDismissListener(this);
+ alert.show();
+ }
+ else if (arg0 == (Button)findViewById(R.id.Continue)) {
+ loadFinalizePage();
+ }
+ else if (arg0 == (Button)findViewById(R.id.ReviewOrder)) {
+ loadReviewPage();
+ }
+ else if (arg0 == (Button)findViewById(R.id.BuyMore)) {
+ loadMainPage();
+ }
+ else if (arg0 == (Button)findViewById(R.id.Done)) {
+ finish();
+ }
+
+ }
+
+ @Override
+ public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
+ long arg3) {
+ //Lets us track the spinner view
+ if (arg0 == findViewById(R.id.Spinner01)) {
+ _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
+ public void onNothingSelected(AdapterView<?> arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void onClick(DialogInterface arg0, int arg1, boolean arg2) {
+ //this is the topping selector
+ if (arg1 == 0) {
+ _cheese = arg2;
+ } else if (arg1 == 1) {
+ _pepperoni = arg2;
+ } else if (arg1 == 2) {
+ _mushrooms = arg2;
+ } else {
+ _onions = arg2;
+ }
+ }
+
+
+ public void paymentSucceeded(String transactionID){
+ //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.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
+ 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
+ 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("");
+ }
+
+
+ @Override
+ public void onDismiss(DialogInterface arg0) {
+ findViewById(R.id.Continue).setVisibility(View.VISIBLE);
+ }
+
+}
View
BIN AndroidDevCamp-March2011/android_devcon-v3.pptx
Binary file not shown.

0 comments on commit d493bb2

Please sign in to comment.