├── FooDelivery_client
├── app
│ ├── .gitignore
│ ├── hs_err_pid6620.log
│ ├── src
│ │ ├── main
│ │ │ ├── res
│ │ │ │ ├── drawable
│ │ │ │ │ ├── login.jpg
│ │ │ │ │ ├── back_pic.png
│ │ │ │ │ ├── mapotofu.jpg
│ │ │ │ │ ├── shuizhubeef.jpg
│ │ │ │ │ ├── sichuanfood.jpg
│ │ │ │ │ ├── sichuanpic.png
│ │ │ │ │ ├── kongpaojiding.jpg
│ │ │ │ │ └── edit_text_selector.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── values
│ │ │ │ │ ├── colors.xml
│ │ │ │ │ ├── dimens.xml
│ │ │ │ │ ├── styles.xml
│ │ │ │ │ └── strings.xml
│ │ │ │ ├── values-v21
│ │ │ │ │ └── styles.xml
│ │ │ │ ├── values-w820dp
│ │ │ │ │ └── dimens.xml
│ │ │ │ ├── menu
│ │ │ │ │ └── menu_main.xml
│ │ │ │ └── layout
│ │ │ │ │ ├── customerui_fragment_customer.xml
│ │ │ │ │ ├── login_activity_login.xml
│ │ │ │ │ ├── customerui_activity_place_order.xml
│ │ │ │ │ ├── login_activity_customer_register.xml
│ │ │ │ │ ├── login_activity_restaurant_register.xml
│ │ │ │ │ ├── customerui_fragment_myorderitem.xml
│ │ │ │ │ ├── customerui_fragment_searchitem.xml
│ │ │ │ │ ├── restaurantui_fragment_menuitem.xml
│ │ │ │ │ ├── restaurantui_fragment_orderitem.xml
│ │ │ │ │ ├── restaurantui_activity_restaurant.xml
│ │ │ │ │ ├── customerui_activity_customer.xml
│ │ │ │ │ ├── customerui_placeorderitem.xml
│ │ │ │ │ ├── customerui_fragment_myorder.xml
│ │ │ │ │ ├── restaurantui_fragment_order.xml
│ │ │ │ │ ├── login_content_login.xml
│ │ │ │ │ ├── customerui_fragment_search.xml
│ │ │ │ │ ├── login_content_customer_register.xml
│ │ │ │ │ ├── customerui_fragment_profile.xml
│ │ │ │ │ ├── customerui_content_place_order.xml
│ │ │ │ │ └── restaurantui_fragment_menu.xml
│ │ │ ├── java
│ │ │ │ └── foodeliver
│ │ │ │ │ ├── utility
│ │ │ │ │ ├── ShowToast.java
│ │ │ │ │ ├── Transition.java
│ │ │ │ │ ├── PictureSearch.java
│ │ │ │ │ └── DataSearch.java
│ │ │ │ │ ├── entities
│ │ │ │ │ ├── Menu.java
│ │ │ │ │ ├── User.java
│ │ │ │ │ ├── FoodMenu.java
│ │ │ │ │ ├── Food.java
│ │ │ │ │ ├── Order.java
│ │ │ │ │ ├── Customer.java
│ │ │ │ │ ├── Restaurant.java
│ │ │ │ │ └── FoodOrder.java
│ │ │ │ │ ├── remote
│ │ │ │ │ ├── DBTask.java
│ │ │ │ │ ├── GetPicture.java
│ │ │ │ │ └── Client.java
│ │ │ │ │ ├── login
│ │ │ │ │ ├── CustomerRegisterActivity.java
│ │ │ │ │ ├── RestaurantRegisterActivity.java
│ │ │ │ │ └── LoginActivity.java
│ │ │ │ │ ├── exception
│ │ │ │ │ └── ConnectionException.java
│ │ │ │ │ ├── restaurantui
│ │ │ │ │ ├── RestaurantActivity.java
│ │ │ │ │ └── RestaurantProfileFragment.java
│ │ │ │ │ └── customerui
│ │ │ │ │ ├── CustomerProfileFragment.java
│ │ │ │ │ ├── CustomerActivity.java
│ │ │ │ │ ├── PlaceOrderActivity.java
│ │ │ │ │ └── SearchFragment.java
│ │ │ └── AndroidManifest.xml
│ │ ├── test
│ │ │ └── java
│ │ │ │ └── jiaqiz
│ │ │ │ └── cmu
│ │ │ │ └── edu
│ │ │ │ └── foodeliver
│ │ │ │ └── ExampleUnitTest.java
│ │ └── androidTest
│ │ │ └── java
│ │ │ └── jiaqiz
│ │ │ └── cmu
│ │ │ └── edu
│ │ │ └── foodeliver
│ │ │ └── ApplicationTest.java
│ ├── proguard-rules.pro
│ └── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── FooDelivery_server
├── build
│ └── web
│ │ ├── WEB-INF
│ │ ├── classes
│ │ │ ├── .netbeans_automatic_build
│ │ │ ├── .netbeans_update_resources
│ │ │ └── remote
│ │ │ │ └── ServerServlet.class
│ │ ├── lib
│ │ │ └── mysql-connector-java-5.1.38-bin.jar
│ │ └── web.xml
│ │ ├── META-INF
│ │ ├── MANIFEST.MF
│ │ └── context.xml
│ │ └── index.html
├── src
│ ├── conf
│ │ └── MANIFEST.MF
│ └── java
│ │ └── remote
│ │ └── ServerServlet.java
├── web
│ ├── META-INF
│ │ └── context.xml
│ ├── index.html
│ └── WEB-INF
│ │ └── web.xml
├── dist
│ └── FooDelivery.war
├── nbproject
│ ├── genfiles.properties
│ ├── private
│ │ ├── private.xml
│ │ └── private.properties
│ ├── project.xml
│ ├── ant-deploy.xml
│ └── project.properties
└── build.xml
└── README.md
/FooDelivery_client/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/FooDelivery_client/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/WEB-INF/classes/.netbeans_automatic_build:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/WEB-INF/classes/.netbeans_update_resources:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/FooDelivery_server/src/conf/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 |
3 |
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 |
3 |
--------------------------------------------------------------------------------
/FooDelivery_server/web/META-INF/context.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/META-INF/context.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/FooDelivery_server/dist/FooDelivery.war:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_server/dist/FooDelivery.war
--------------------------------------------------------------------------------
/FooDelivery_client/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/hs_err_pid6620.log:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/hs_err_pid6620.log
--------------------------------------------------------------------------------
/FooDelivery_client/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/login.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/drawable/login.jpg
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/back_pic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/drawable/back_pic.png
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/mapotofu.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/drawable/mapotofu.jpg
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/shuizhubeef.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/drawable/shuizhubeef.jpg
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/sichuanfood.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/drawable/sichuanfood.jpg
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/sichuanpic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/drawable/sichuanpic.png
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/kongpaojiding.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/drawable/kongpaojiding.jpg
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_client/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/WEB-INF/classes/remote/ServerServlet.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_server/build/web/WEB-INF/classes/remote/ServerServlet.class
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/WEB-INF/lib/mysql-connector-java-5.1.38-bin.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/catherine629/Android-App-FooDelivery/HEAD/FooDelivery_server/build/web/WEB-INF/lib/mysql-connector-java-5.1.38-bin.jar
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/utility/ShowToast.java:
--------------------------------------------------------------------------------
1 | package foodeliver.utility;
2 |
3 | /**
4 | * Show Toast interface.
5 | * @author Jiaqi Zhang
6 | */
7 | public interface ShowToast {
8 |
9 | public void setToast(String str);
10 | }
11 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/utility/Transition.java:
--------------------------------------------------------------------------------
1 | package foodeliver.utility;
2 |
3 | /**
4 | * Transition interface.
5 | * @author Jiaqi Zhang
6 | */
7 | public interface Transition {
8 |
9 | public void transit();
10 | public void setToast(String str);
11 | }
12 |
--------------------------------------------------------------------------------
/FooDelivery_client/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/drawable/edit_text_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/utility/PictureSearch.java:
--------------------------------------------------------------------------------
1 | package foodeliver.utility;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Picture Search Interface.
9 | * @author Jiaqi Zhang
10 | */
11 | public interface PictureSearch {
12 |
13 | public void pictureReady(ArrayList pictures);
14 | }
15 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #2E7D32
4 | #2E7D32
5 | #FF4081
6 | #000000
7 | #000010
8 |
9 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 8dp
7 | 16dp
8 |
9 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/utility/DataSearch.java:
--------------------------------------------------------------------------------
1 | package foodeliver.utility;
2 |
3 | /**
4 | * Data search interface.
5 | * @author Jiaqi Zhang
6 | */
7 | public interface DataSearch {
8 |
9 | public void dbResultReady(String result);
10 | public void updateReady(String result);
11 | public void dbDetailReady(String result);
12 | public void deleteReady(String result);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/test/java/jiaqiz/cmu/edu/foodeliver/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package foodeliver;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/androidTest/java/jiaqiz/cmu/edu/foodeliver/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package jiaqiz.cmu.edu.foodeliver;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/FooDelivery_server/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=51df08d1
2 | build.xml.script.CRC32=a025eff8
3 | build.xml.stylesheet.CRC32=651128d4@1.75.1.1
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=51df08d1
7 | nbproject/build-impl.xml.script.CRC32=bccb6365
8 | nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.75.1.1
9 |
--------------------------------------------------------------------------------
/FooDelivery_server/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 | TODO supply a title
10 |
11 |
12 |
13 |
14 | TODO write content
15 |
16 |
17 |
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 | TODO supply a title
10 |
11 |
12 |
13 |
14 | TODO write content
15 |
16 |
17 |
--------------------------------------------------------------------------------
/FooDelivery_server/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | file:/C:/Users/cathe/Documents/NetBeansProjects/FooDelivery/src/java/remote/ServerServlet.java
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/FooDelivery_client/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/FooDelivery_server/nbproject/private/private.properties:
--------------------------------------------------------------------------------
1 | deploy.ant.properties.file=C:\\Users\\cathe\\AppData\\Roaming\\NetBeans\\8.1\\tomcat80.properties
2 | j2ee.server.domain=C:/Users/cathe/AppData/Roaming/NetBeans/8.1/apache-tomcat-8.0.27.0_base
3 | j2ee.server.home=C:/Program Files/Apache Software Foundation/Apache Tomcat 8.0.27
4 | j2ee.server.instance=tomcat80:home=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 8.0.27:base=apache-tomcat-8.0.27.0_base
5 | javac.debug=true
6 | javadoc.preview=true
7 | selected.browser=default
8 | user.properties.file=C:\\Users\\cathe\\AppData\\Roaming\\NetBeans\\8.1\\build.properties
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #FooDelivery - Android App
2 |
3 | Developed by Shuhui Yang, Jiaqi Zhang, and Yu Qiu
4 |
5 | ##Overview
6 |
7 | FooDelivery is an O2O platform that provides connection between online/physical restaurants and offline consumers. FooDelivery offers both restaurant and consumer interfaces. Restaurant owners can manage menu, receive orders and process delivery while consumers are able to browse or search restaurants, scan the menu and place orders.
8 |
9 | ## Directory
10 |
11 | 1. Server Code (Netbeans Project)
12 | 2. Client Code (Android Studio Project)
13 | - Login Package
14 | - Customer Package
15 | - Resturant Package
16 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/jacie/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/FooDelivery_server/web/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ServerServlet
5 | remote.ServerServlet
6 |
7 |
8 | ServerServlet
9 | /ServerServlet
10 |
11 |
12 |
13 | 30
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/FooDelivery_server/build/web/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ServerServlet
5 | remote.ServerServlet
6 |
7 |
8 | ServerServlet
9 | /ServerServlet
10 |
11 |
12 |
13 | 30
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_fragment_customer.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "jiaqiz.cmu.edu.foodeliver"
9 | minSdkVersion 22
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.2.1'
26 | compile 'com.android.support:design:23.2.1'
27 | compile 'com.android.support:recyclerview-v7:23.2.1'
28 | }
29 |
--------------------------------------------------------------------------------
/FooDelivery_client/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/FooDelivery_server/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.web.project
4 |
5 |
6 | FooDelivery
7 | 1.6.5
8 |
9 |
10 | ${file.reference.mysql-connector-java-5.1.38-bin.jar}
11 | WEB-INF/lib
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/login_activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_activity_place_order.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/login_activity_customer_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/login_activity_restaurant_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_fragment_myorderitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
27 |
28 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/Menu.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | * Abstract Class Menu.
7 | * @param item type
8 | */
9 | public abstract class Menu {
10 | ArrayList items = new ArrayList();
11 | String restaurant;
12 |
13 | /**
14 | * Create item in menu
15 | * @param name name
16 | * @param price price
17 | * @param picture picture
18 | * @return true if successfully
19 | */
20 | abstract public void createItem(String name, double price, Byte[] picture);
21 |
22 | /**
23 | * Read item in menu
24 | * @param name name
25 | * @return item information
26 | */
27 | abstract public void readItem(String name);
28 |
29 | /**
30 | * Update item in menu
31 | * @param name name
32 | * @param price price
33 | * @param picture picture
34 | * @return true if update successfully, false otherwise
35 | */
36 | abstract public void updateItem(String name, double price, Byte[] picture);
37 |
38 | /**
39 | * Delete item in menu
40 | * @param name name
41 | * @return true if delete successfully, false otherwise
42 | */
43 | abstract public void deleteItem(String name);
44 |
45 | /**
46 | * Get items.
47 | * @return items
48 | */
49 | public ArrayList getItems() {
50 | return items;
51 | }
52 |
53 | /**
54 | * Set items
55 | * @param items items
56 | */
57 | public void setItems(ArrayList items) {
58 | this.items = items;
59 | }
60 |
61 | public String getRestaurant() {
62 | return restaurant;
63 | }
64 |
65 | public void setRestaurant(String restaurant) {
66 | this.restaurant = restaurant;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_fragment_searchitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
23 |
24 |
34 |
35 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/restaurantui_fragment_menuitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
27 |
28 |
38 |
39 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/remote/DBTask.java:
--------------------------------------------------------------------------------
1 | package foodeliver.remote;
2 |
3 | import android.os.AsyncTask;
4 |
5 | import java.util.ArrayList;
6 |
7 | import foodeliver.exception.ConnectionException;
8 | import foodeliver.utility.DataSearch;
9 |
10 |
11 | public class DBTask {
12 | DataSearch ds = null;
13 | String type = "result";
14 |
15 | public void getResult(ArrayList sql, DataSearch ds, String type) {
16 | this.ds = ds;
17 | this.type = type;
18 | new GetResTask().execute(sql);
19 | }
20 |
21 | private class GetResTask extends AsyncTask, Void, String> {
22 | protected String doInBackground(ArrayList... sql) {
23 | return search(sql[0]);
24 | }
25 | protected void onPostExecute(String sqlResult) {
26 | if (type.equals("result")) {
27 | ds.dbResultReady(sqlResult);
28 | } else if (type.equals("update")) {
29 | ds.updateReady(sqlResult);
30 | } else if (type.equals("delete")){
31 | ds.deleteReady(sqlResult);
32 | } else {
33 | ds.dbDetailReady(sqlResult);
34 | }
35 | }
36 | private String search(ArrayList sql) {
37 | String results = "";
38 | try {
39 | if (type.equals("update") || type.equals("delete")) {
40 | results = "true";
41 | for (String s : sql) {
42 | if(Client.createData(s).equals("False")) {
43 | results = "false";
44 | }
45 | }
46 | } else {
47 | results = Client.readData(sql.get(0));
48 | }
49 | } catch (ConnectionException e) {
50 | e.printStackTrace();
51 | }
52 | System.out.println("***"+results);
53 | return results;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/restaurantui_fragment_orderitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
27 |
28 |
38 |
39 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/FooDelivery_server/nbproject/ant-deploy.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
25 |
28 |
29 |
30 |
31 |
32 |
34 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
33 |
37 |
41 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/remote/GetPicture.java:
--------------------------------------------------------------------------------
1 | package foodeliver.remote;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.AsyncTask;
6 |
7 | import java.io.BufferedInputStream;
8 | import java.io.IOException;
9 | import java.net.URL;
10 | import java.net.URLConnection;
11 | import java.util.ArrayList;
12 |
13 | import foodeliver.utility.PictureSearch;
14 |
15 |
16 | public class GetPicture {
17 | PictureSearch ps = null;
18 |
19 | public void search(ArrayList searchUrls, PictureSearch ps) {
20 | this.ps = ps;
21 | new AsyncPicSearch().execute(searchUrls);
22 | }
23 |
24 | private class AsyncPicSearch extends AsyncTask, Void, ArrayList> {
25 | protected ArrayList doInBackground(ArrayList... urls) {
26 | System.out.println(urls[0]);
27 | return search(urls[0]);
28 | }
29 |
30 | protected void onPostExecute(ArrayList pictures) {
31 | ps.pictureReady(pictures);
32 | }
33 |
34 | private ArrayList search(ArrayList searchUrls) {
35 | try {
36 | ArrayList results = new ArrayList();
37 | for (String s : searchUrls) {
38 | URL u = new URL(s);
39 | results.add(getImage(u));
40 | }
41 | return results;
42 | } catch (Exception e) {
43 | e.printStackTrace();
44 | return null; // so compiler does not complain
45 | }
46 | }
47 |
48 | private Bitmap getImage(final URL url) {
49 | try {
50 | URLConnection con = url.openConnection();
51 | con.connect();
52 | BufferedInputStream b = new BufferedInputStream(con.getInputStream());
53 | Bitmap bm = BitmapFactory.decodeStream(b);
54 | b.close();
55 | return bm;
56 | } catch (IOException e) {
57 | e.printStackTrace();
58 | return null;
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/restaurantui_activity_restaurant.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
24 |
25 |
26 |
27 |
32 |
33 |
34 |
35 |
40 |
41 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_activity_customer.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
27 |
28 |
33 |
34 |
35 |
36 |
41 |
42 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/User.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import foodeliver.utility.ShowToast;
4 | import foodeliver.utility.Transition;
5 |
6 | /**
7 | * Abstract Class User.
8 | * @author Yu Qiu
9 | */
10 | public abstract class User {
11 | String email; // User email
12 | String phone; // User phone number
13 | String password; // User password
14 | String card; // User card number
15 | String address; // User address
16 | ShowToast showToast;
17 | Transition transition;
18 |
19 | abstract void createProfile(String[] params);
20 | /**
21 | * Read profile.
22 | * @param email email
23 | * @return profile information
24 | */
25 | abstract void readProfile(String email);
26 |
27 | abstract void updateProfile(String[] params);
28 |
29 | /**
30 | * Delete profile.
31 | * @param email email address as the key
32 | * @return true if delete successfully, false otherwise
33 | */
34 | abstract void deleteProfile(String email);
35 |
36 | // Get e-mail
37 | public String getEmail() {
38 | return email;
39 | }
40 | // Set e-mail
41 | public void setEmail(String email) {
42 | this.email = email;
43 | }
44 | // Get phone
45 | public String getPhone() {
46 | return phone;
47 | }
48 | // Set phone
49 | public void setPhone(String phone) {
50 | this.phone = phone;
51 | }
52 | // Get password
53 | public String getPassword() {
54 | return password;
55 | }
56 | // Set password
57 | public void setPassword(String password) {
58 | this.password = password;
59 | }
60 | // Get card
61 | public String getCard() {
62 | return card;
63 | }
64 | // Set card
65 | public void setCard(String card) {
66 | this.card = card;
67 | }
68 | // Get address
69 | public String getAddress() {
70 | return address;
71 | }
72 | // Set address
73 | public void setAddress(String address) {
74 | this.address = address;
75 | }
76 |
77 | public void setShowToast (ShowToast st) {
78 | showToast = st;
79 | }
80 |
81 | public void setTransition(Transition r) {
82 | transition = r;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_placeorderitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
17 |
18 |
28 |
29 |
36 |
37 |
47 |
48 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/FoodMenu.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import java.util.ArrayList;
6 |
7 | import foodeliver.remote.DBTask;
8 | import foodeliver.remote.GetPicture;
9 | import foodeliver.utility.DataSearch;
10 | import foodeliver.utility.PictureSearch;
11 |
12 | /**
13 | * Food Menu class.
14 | * @author Yu Qiu
15 | */
16 | public class FoodMenu extends Menu implements DataSearch, PictureSearch {
17 |
18 | @Override
19 | public void createItem(String name, double price, Byte[] picture) {
20 |
21 | }
22 |
23 | @Override
24 | public void readItem(String email) {
25 | this.setRestaurant(email);
26 | String sql = "SELECT * FROM MENU WHERE RestaurantEmail='" + email +"';";
27 | DBTask dbT = new DBTask();
28 | ArrayList list = new ArrayList();
29 | list.add(sql);
30 | dbT.getResult(list, FoodMenu.this, "result");
31 | }
32 |
33 | @Override
34 | public void updateItem(String name, double price, Byte[] picture) {
35 |
36 | }
37 |
38 | @Override
39 | public void deleteItem(String name) {
40 |
41 | }
42 |
43 | @Override
44 | public void dbResultReady(String result) {
45 | System.out.println("SQL Result: " + result);
46 | ArrayList searchPics = new ArrayList();
47 | String[] foods = result.split("\n");
48 | for (String food: foods){
49 | String[] elements = food.split("\t");
50 | this.items.add(new Food(elements[0], elements[2], elements[3], elements[4]));
51 | searchPics.add(elements[4]);
52 | }
53 | GetPicture gp = new GetPicture();
54 | System.out.println("gongpaojiding:"+searchPics.get(0));
55 | gp.search(searchPics, FoodMenu.this);
56 | }
57 |
58 | @Override
59 | public void updateReady(String result) {
60 | }
61 |
62 | @Override
63 | public void dbDetailReady(String result) {
64 | }
65 |
66 | @Override
67 | public void deleteReady(String result) {
68 |
69 | }
70 |
71 | @Override
72 | public void pictureReady(ArrayList pictures) {
73 | for (int i = 0; i < pictures.size(); i++){
74 | System.out.println("picture:"+pictures.get(i));
75 | items.get(i).setPicture(pictures.get(i));
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/FooDelivery_client/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/Food.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import java.util.ArrayList;
6 |
7 | import foodeliver.remote.GetPicture;
8 | import foodeliver.utility.PictureSearch;
9 |
10 | /**
11 | * Food Class.
12 | * @author Yu Qiu
13 | */
14 | public class Food{
15 |
16 | String id;
17 | String name;
18 | String price;
19 | String pictureURL;
20 | Bitmap picture;
21 | boolean seleted;
22 | int quantity;
23 |
24 |
25 | public Food(){}
26 | public Food(String id, String name, String price){
27 | this.id = id;
28 | this.name = name;
29 | this.price = price;
30 | }
31 | public Food(String id, String name, String price, int quantity){
32 | this(id, name, price);
33 | this.quantity = quantity;
34 | }
35 |
36 |
37 | public Food(String id, String name, String price, String pictureURL){
38 | this(id, name, price);
39 | this.pictureURL = pictureURL;
40 | }
41 |
42 | public String getId() {
43 | return id;
44 | }
45 |
46 | public void setId(String id) {
47 | this.id = id;
48 | }
49 |
50 | public String getPictureURL() {
51 | return pictureURL;
52 | }
53 |
54 | public void setPictureURL(String pictureURL) {
55 | this.pictureURL = pictureURL;
56 | }
57 |
58 | public boolean isSeleted() {
59 | return seleted;
60 | }
61 |
62 | public int getQuantity() {
63 | return quantity;
64 | }
65 |
66 | public void setQuantity(int quantity) {
67 | this.quantity = quantity;
68 | }
69 |
70 | public void setSeleted(boolean seleted) {
71 | this.seleted = seleted;
72 | }
73 |
74 | /**
75 | * Get name.
76 | * @return name
77 | */
78 | public String getName() {
79 | return name;
80 | }
81 |
82 | /**
83 | * Get price.
84 | * @return price
85 | */
86 | public String getPrice() {
87 | return price;
88 | }
89 |
90 | /**
91 | * Get picture.
92 | * @return picture
93 | */
94 | public Bitmap getPicture() {
95 | return picture;
96 | }
97 |
98 | /**
99 | * Set food name.
100 | * @param name food name
101 | */
102 | public void setName(String name) {
103 | this.name = name;
104 | }
105 |
106 | /**
107 | * Set price
108 | * @param price price
109 | */
110 | public void setPrice(String price) {
111 | this.price = price;
112 | }
113 |
114 | /**
115 | * Set picture
116 | * @param picture picture
117 | */
118 | public void setPicture(Bitmap picture) {
119 | this.picture = picture;
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/Order.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import java.util.ArrayList;
4 |
5 | import foodeliver.utility.ShowToast;
6 |
7 | /**
8 | * Abstract class Order.
9 | * @param item type
10 | */
11 | public abstract class Order {
12 | String orderId; // Order number
13 | String timestamp; // Timestamp
14 | double price; // Food price
15 | String status; // Order status
16 | ArrayList items;
17 | ShowToast showToast;
18 |
19 | abstract void createOrder(String customerEmail, String restaurantEmail, String orderTime,
20 | String phone, String addr, String payment, double totalPrice, ArrayList items);
21 |
22 | abstract void readOrder();
23 |
24 | abstract void updateOrder(String orderId, String name, String status, String p);
25 |
26 | /**
27 | * Delete order.
28 | * @param orderID order number
29 | * @return true if successfully, false otherwise
30 | */
31 | abstract void deleteOrder(String orderID);
32 |
33 | abstract void showOrderDetails();
34 |
35 | /**
36 | * Get items.
37 | * @return items
38 | */
39 | public ArrayList getItems() {
40 | return items;
41 | }
42 |
43 | /**
44 | * Set items.
45 | * @param items items
46 | */
47 | public void setItems(ArrayList items) {
48 | this.items = items;
49 | }
50 |
51 | /**
52 | * Get order number.
53 | * @return order number
54 | */
55 | public String getOrderId() {
56 | return orderId;
57 | }
58 |
59 | /**
60 | * Set order number.
61 | * @param orderId order number
62 | */
63 | public void setOrderId(String orderId) {
64 | this.orderId = orderId;
65 | }
66 |
67 | /**
68 | * Get timestamp.
69 | * @return timestamp
70 | */
71 | public String getTimestamp() {
72 | return timestamp;
73 | }
74 |
75 | /**
76 | * Set timestamp.
77 | * @param timestamp timestamp
78 | */
79 | public void setTimestamp(String timestamp) {
80 | this.timestamp = timestamp;
81 | }
82 |
83 | /**
84 | * Get price.
85 | * @return price
86 | */
87 | public double getPrice() {
88 | return price;
89 | }
90 |
91 | /**
92 | * Set price.
93 | * @param price price
94 | */
95 | public void setPrice(double price) {
96 | this.price = price;
97 | }
98 | // Get status
99 |
100 | /**
101 | * Get status.
102 | * @return status
103 | */
104 | public String getStatus() {
105 | return status;
106 | }
107 |
108 | /**
109 | * Set status.
110 | * @param status status
111 | */
112 | public void setStatus(String status) {
113 | this.status = status;
114 | }
115 |
116 | public void setShowToast (ShowToast st) {
117 | showToast = st;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/Customer.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import java.util.ArrayList;
4 |
5 | import foodeliver.utility.DataSearch;
6 | import foodeliver.remote.DBTask;
7 |
8 | /**
9 | * Customer Class.
10 | * @author Yu Qiu
11 | */
12 | public class Customer extends User implements DataSearch {
13 |
14 | boolean toCreate = false;
15 |
16 | @Override
17 | public void createProfile(String[] params) {
18 | this.email = params[0];
19 | this.phone = params[1];
20 | this.password = params[2];
21 | this.card = params[3];
22 | this.address = params[4];
23 | String sql = "INSERT INTO CONSUMER VALUES ('" + email + "','"
24 | + phone + "','" + password + "','"
25 | + card + "','" + address + "')";
26 | toCreate = true;
27 | DBTask dbT = new DBTask();
28 | ArrayList list = new ArrayList();
29 | list.add(sql);
30 | dbT.getResult(list, this, "update");
31 | }
32 |
33 | @Override
34 | public void readProfile(String email) {
35 | this.email = email;
36 | DBTask dbT = new DBTask();
37 | ArrayList list = new ArrayList();
38 | list.add("SELECT Email, Password, CardNumber, Address, Phone" +
39 | " FROM CONSUMER WHERE Email='" + email + "';");
40 | dbT.getResult(list, this, "result");
41 | }
42 |
43 | @Override
44 | public void updateProfile(String[] params) {
45 | if (params.length > 3) {
46 | this.phone = params[0];
47 | this.password = params[1];
48 | this.card = params[2];
49 | this.address = params[3];
50 | toCreate = false;
51 | DBTask dbT = new DBTask();
52 | ArrayList list = new ArrayList();
53 | list.add("UPDATE CONSUMER SET Password='" + password
54 | + "', Phone='" + phone + "', CardNumber='" + card + "', Address='"
55 | + address + "' WHERE Email='" + email + "';");
56 | dbT.getResult(list, this, "update");
57 | }
58 | }
59 |
60 | @Override
61 | public void deleteProfile(String email) {
62 | }
63 |
64 | public void dbResultReady(String result) {
65 | System.out.println("SQL Result: " + result);
66 | String[] elements = result.split("\t");
67 | password = elements[1];
68 | card = elements[2];
69 | address = elements[3];
70 | phone = elements[4];
71 | }
72 |
73 | public void dbDetailReady(String result) {}
74 |
75 | @Override
76 | public void deleteReady(String result) {
77 |
78 | }
79 |
80 |
81 | public void updateReady(String result) {
82 | if (result.equals("true")) {
83 | if (toCreate) {
84 | transition.setToast("New profile created.");
85 | transition.transit();
86 | } else {
87 | showToast.setToast("New profile saved successfully.");
88 | }
89 | } else {
90 | if (toCreate) {
91 | transition.setToast("Sorry, the account already exists.");
92 | } else {
93 | showToast.setToast("Sorry, save failed.");
94 | }
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_fragment_myorder.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
16 |
17 |
28 |
29 |
40 |
41 |
52 |
53 |
60 |
61 |
72 |
73 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/login/CustomerRegisterActivity.java:
--------------------------------------------------------------------------------
1 | package foodeliver.login;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.EditText;
10 | import android.widget.Toast;
11 |
12 | import foodeliver.R;
13 | import foodeliver.entities.Customer;
14 | import foodeliver.utility.Transition;
15 | import foodeliver.utility.Transition;
16 |
17 | /**
18 | * Customer Register Activity.
19 | * @author Yu Qiu
20 | */
21 | public class CustomerRegisterActivity extends AppCompatActivity implements Transition {
22 | EditText registerEmailText;
23 | EditText registerPasswordText;
24 | EditText registerConfirmPasswordText;
25 | EditText registerCardText;
26 | EditText registerAddressText;
27 | EditText registerPhoneText;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.login_activity_customer_register);
33 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
34 | setSupportActionBar(toolbar);
35 |
36 | Button register = (Button) findViewById(R.id.register_submit_customer_button);
37 |
38 | register.setOnClickListener(new View.OnClickListener() {
39 | @Override
40 | public void onClick(View view) {
41 | registerEmailText = (EditText)findViewById(R.id.register_email_text);
42 | registerPasswordText = (EditText)findViewById(R.id.register_password_text);
43 | registerConfirmPasswordText = (EditText)findViewById(R.id.register_confirm_password_text);
44 | registerCardText = (EditText)findViewById(R.id.register_card_text);
45 | registerAddressText = (EditText)findViewById(R.id.register_address_text);
46 | registerPhoneText = (EditText)findViewById(R.id.register_phone_text);
47 | if (!registerPasswordText.getText().toString().trim().
48 | equals(registerConfirmPasswordText.getText().toString().trim())) {
49 | Toast.makeText(CustomerRegisterActivity.this,
50 | "Confirmed password is not consistent.", Toast.LENGTH_LONG).show();
51 | } else {
52 | String[] params = new String[5];
53 | params[0] = registerEmailText.getText().toString();
54 | params[1] = registerPhoneText.getText().toString();
55 | params[2] = registerPasswordText.getText().toString();
56 | params[3] = registerCardText.getText().toString();
57 | params[4] = registerAddressText.getText().toString();
58 | Customer c = new Customer();
59 | c.setTransition(CustomerRegisterActivity.this);
60 | c.createProfile(params);
61 | }
62 | }
63 | });
64 | }
65 |
66 | public void transit() {
67 | Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
68 | startActivity(intent);
69 | }
70 |
71 | @Override
72 | public void setToast(String str) {
73 | Toast.makeText(this, str, Toast.LENGTH_LONG).show();
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/FooDelivery_server/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Builds, tests, and runs the project FooDelivery.
12 |
13 |
71 |
72 |
--------------------------------------------------------------------------------
/FooDelivery_server/src/java/remote/ServerServlet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package remote;
7 |
8 | import java.io.IOException;
9 | import java.io.PrintWriter;
10 | import java.sql.Connection;
11 | import java.sql.DriverManager;
12 | import java.sql.ResultSet;
13 | import java.sql.ResultSetMetaData;
14 | import java.sql.SQLException;
15 | import java.sql.Statement;
16 | import javax.servlet.ServletException;
17 | import javax.servlet.http.HttpServlet;
18 | import javax.servlet.http.HttpServletRequest;
19 | import javax.servlet.http.HttpServletResponse;
20 |
21 | /**
22 | *
23 | * @author cathe
24 | */
25 | public class ServerServlet extends HttpServlet {
26 |
27 | // JDBC driver name and database URL
28 | static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
29 | static final String DB_RUL = "jdbc:mysql://localhost:3306/FooDelivery";
30 |
31 | // Database credentials
32 | static final String USER = "root";
33 | static final String PASSWORD = "root";
34 |
35 | private static Connection conn = null;
36 |
37 | /**
38 | * @see HttpServlet#HttpServlet()
39 | */
40 | public ServerServlet() {
41 | try {
42 | Class.forName(JDBC_DRIVER);
43 | conn = DriverManager.getConnection(DB_RUL, USER, PASSWORD);
44 | } catch (ClassNotFoundException e) {
45 | // TODO Auto-generated catch block
46 | e.printStackTrace();
47 | } catch (SQLException e) {
48 | // TODO Auto-generated catch block
49 | e.printStackTrace();
50 | }
51 | }
52 |
53 | //
54 | /**
55 | * Handles the HTTP GET method.
56 | *
57 | * @param request servlet request
58 | * @param response servlet response
59 | * @throws ServletException if a servlet-specific error occurs
60 | * @throws IOException if an I/O error occurs
61 | */
62 | @Override
63 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
64 | PrintWriter writer = new PrintWriter(response.getOutputStream());
65 | // parse parameters
66 | String sql = request.getParameter("sql");
67 | String method = request.getParameter("method");
68 | // prepare sql
69 | Statement stmt;
70 | try {
71 | stmt = conn.createStatement();
72 | // decide methods
73 | if (method.equals("read")){
74 | // execute read operation
75 | StringBuilder sb = new StringBuilder();
76 | ResultSet rs = stmt.executeQuery(sql);
77 | ResultSetMetaData rsmd = rs.getMetaData();
78 | int columnNumber = rsmd.getColumnCount();
79 | while (rs.next()){
80 | for (int i = 1; i <= columnNumber; i++){
81 | sb.append(rs.getString(i)).append("\t");
82 | }
83 | sb.append("\n");
84 | }
85 | System.out.println(sb.toString());
86 | writer.write(sb.toString());
87 | } else {
88 | // execute update operation
89 | int result = stmt.executeUpdate(sql);
90 | System.out.println(result);
91 | if (result == 0){
92 | writer.write("False");
93 | } else {
94 | writer.write("True");
95 | }
96 | }
97 | } catch (SQLException e) {
98 | writer.write(e.getMessage());
99 | e.printStackTrace();
100 | } finally {
101 | if (writer != null) {
102 | writer.close();
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/FooDelivery_server/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | annotation.processing.enabled=true
2 | annotation.processing.enabled.in.editor=true
3 | annotation.processing.processors.list=
4 | annotation.processing.run.all.processors=true
5 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
6 | build.classes.dir=${build.web.dir}/WEB-INF/classes
7 | build.classes.excludes=**/*.java,**/*.form
8 | build.dir=build
9 | build.generated.dir=${build.dir}/generated
10 | build.generated.sources.dir=${build.dir}/generated-sources
11 | build.test.classes.dir=${build.dir}/test/classes
12 | build.test.results.dir=${build.dir}/test/results
13 | build.web.dir=${build.dir}/web
14 | build.web.excludes=${build.classes.excludes}
15 | client.urlPart=
16 | compile.jsps=false
17 | conf.dir=${source.root}/conf
18 | debug.classpath=${build.classes.dir}:${javac.classpath}
19 | debug.test.classpath=\
20 | ${run.test.classpath}
21 | display.browser=true
22 | # Files to be excluded from distribution war
23 | dist.archive.excludes=
24 | dist.dir=dist
25 | dist.ear.war=${dist.dir}/${war.ear.name}
26 | dist.javadoc.dir=${dist.dir}/javadoc
27 | dist.war=${dist.dir}/${war.name}
28 | endorsed.classpath=\
29 | ${libs.javaee-endorsed-api-7.0.classpath}
30 | excludes=
31 | file.reference.mysql-connector-java-5.1.38-bin.jar=C:\\Users\\cathe\\Downloads\\mysql-connector-java-5.1.38-bin.jar
32 | includes=**
33 | j2ee.compile.on.save=true
34 | j2ee.copy.static.files.on.save=true
35 | j2ee.deploy.on.save=true
36 | j2ee.platform=1.7-web
37 | j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
38 | j2ee.server.type=Tomcat
39 | jar.compress=false
40 | javac.classpath=\
41 | ${file.reference.mysql-connector-java-5.1.38-bin.jar}
42 | # Space-separated list of extra javac options
43 | javac.compilerargs=
44 | javac.debug=true
45 | javac.deprecation=false
46 | javac.processorpath=\
47 | ${javac.classpath}
48 | javac.source=1.8
49 | javac.target=1.8
50 | javac.test.classpath=\
51 | ${javac.classpath}:\
52 | ${build.classes.dir}
53 | javac.test.processorpath=\
54 | ${javac.test.classpath}
55 | javadoc.additionalparam=
56 | javadoc.author=false
57 | javadoc.encoding=${source.encoding}
58 | javadoc.noindex=false
59 | javadoc.nonavbar=false
60 | javadoc.notree=false
61 | javadoc.preview=true
62 | javadoc.private=false
63 | javadoc.splitindex=true
64 | javadoc.use=true
65 | javadoc.version=false
66 | javadoc.windowtitle=
67 | lib.dir=${web.docbase.dir}/WEB-INF/lib
68 | persistence.xml.dir=${conf.dir}
69 | platform.active=default_platform
70 | resource.dir=setup
71 | run.test.classpath=\
72 | ${javac.test.classpath}:\
73 | ${build.test.classes.dir}
74 | # Space-separated list of JVM arguments used when running a class with a main method or a unit test
75 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
76 | runmain.jvmargs=
77 | source.encoding=UTF-8
78 | source.root=src
79 | src.dir=${source.root}/java
80 | test.src.dir=test
81 | war.content.additional=
82 | war.ear.name=${war.name}
83 | war.name=FooDelivery.war
84 | web.docbase.dir=web
85 | webinf.dir=web/WEB-INF
86 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/restaurantui_fragment_order.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
13 |
14 |
25 |
26 |
37 |
38 |
49 |
50 |
61 |
62 |
63 |
70 |
71 |
80 |
81 |
82 |
83 |
90 |
91 |
99 |
100 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/login/RestaurantRegisterActivity.java:
--------------------------------------------------------------------------------
1 | package foodeliver.login;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.EditText;
10 | import android.widget.Spinner;
11 | import android.widget.Toast;
12 |
13 | import foodeliver.R;
14 | import foodeliver.entities.Restaurant;
15 | import foodeliver.utility.Transition;
16 |
17 | /**
18 | * Restaurant Register Activity.
19 | * @author Yu Qiu
20 | */
21 | public class RestaurantRegisterActivity extends AppCompatActivity implements Transition{
22 | EditText registerRestaurantNameText;
23 | EditText registerRestaurantEmailText;
24 | EditText registerRestaurantPhoneText;
25 | EditText registerRestaurantPasswordText;
26 | EditText registerRestaurantConfirmPasswordText;
27 | EditText registerRestaurantCardText;
28 | EditText registerRestaurantAddressText;
29 | Spinner spinnerLocation;
30 | Spinner spinnerCategory;
31 | EditText registerImageUrl;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.login_activity_restaurant_register);
37 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
38 | setSupportActionBar(toolbar);
39 |
40 | Button register = (Button) findViewById(R.id.register_restaurant_submit_button);
41 | register.setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View view) {
44 | registerRestaurantNameText = (EditText)findViewById(R.id.register_restaurant_name_text);
45 | registerRestaurantEmailText = (EditText)findViewById(R.id.register_restaurant_email_text);
46 | registerRestaurantPhoneText = (EditText)findViewById(R.id.register_restaurant_phone_text);
47 | registerRestaurantPasswordText = (EditText)findViewById(R.id.register_restaurant_password_text);
48 | registerRestaurantConfirmPasswordText = (EditText)findViewById(R.id.register_restaurant_confirm_password_text);
49 | registerRestaurantCardText = (EditText)findViewById(R.id.register_restaurant_card_text);
50 | registerRestaurantAddressText = (EditText)findViewById(R.id.register_restaurant_address_text);
51 | spinnerLocation = (Spinner)findViewById(R.id.spinner_location);
52 | spinnerCategory = (Spinner)findViewById(R.id.spinner_category);
53 | registerImageUrl = (EditText)findViewById(R.id.register_image_url);
54 |
55 | if (!registerRestaurantPasswordText.getText().toString().
56 | equals(registerRestaurantConfirmPasswordText.getText().toString())) {
57 | Toast.makeText(RestaurantRegisterActivity.this,
58 | "Confirmed password is not consistent.", Toast.LENGTH_LONG).show();
59 | } else {
60 | String[] params = new String[9];
61 | params[0] = registerRestaurantEmailText.getText().toString();
62 | params[1] = registerRestaurantNameText.getText().toString();
63 | params[2] = registerRestaurantPhoneText.getText().toString();
64 | params[3] = registerRestaurantPasswordText.getText().toString();
65 | params[4] = registerRestaurantCardText.getText().toString();
66 | params[5] = registerRestaurantAddressText.getText().toString();
67 | params[6] = spinnerCategory.getSelectedItem().toString();
68 | params[7] = spinnerLocation.getSelectedItem().toString();
69 | params[8] = registerImageUrl.getText().toString();
70 | Restaurant r = new Restaurant();
71 | r.setTransition(RestaurantRegisterActivity.this);
72 | r.createProfile(params);
73 | }
74 | }
75 | });
76 | }
77 |
78 | public void transit() {
79 | Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
80 | startActivity(intent);
81 | }
82 |
83 | @Override
84 | public void setToast(String str) {
85 | Toast.makeText(this, str, Toast.LENGTH_LONG).show();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/login_content_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
23 |
24 |
36 |
37 |
48 |
49 |
60 |
61 |
70 |
71 |
82 |
83 |
94 |
95 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/exception/ConnectionException.java:
--------------------------------------------------------------------------------
1 | package foodeliver.exception;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Connection Exception class.
7 | * @Author Jiaqi Zhang
8 | */
9 | public class ConnectionException extends Exception {
10 |
11 | /**
12 | * Error Number.
13 | */
14 | private int errorNo;
15 |
16 | /**
17 | * Error Message.
18 | */
19 | private String errorMsg;
20 |
21 | /**
22 | * Error number set.
23 | */
24 | private static final int [] ERROR_NO_SET = new int [] {1};
25 |
26 | /**
27 | * Error message set.
28 | */
29 | private static final String [] ERROR_MSG_SET
30 | = new String [] {"Connection Error."};
31 |
32 | /**
33 | * Default serialize ID.
34 | */
35 | private static final long serialVersionUID = 1L;
36 |
37 | /**
38 | * Constructor with no argument.
39 | */
40 | public ConnectionException() {
41 | super();
42 | printEmptyException();
43 | }
44 |
45 | /**
46 | * Constructor.
47 | * @param errorNo error number
48 | */
49 | public ConnectionException(int errorNo) {
50 | super();
51 | int index = findErrorNo(errorNo);
52 | if (index != -1) {
53 | this.errorNo = errorNo;
54 | }
55 | errorMsg = ERROR_MSG_SET[index];
56 | printEmptyException();
57 | }
58 |
59 | /**
60 | * Constructor.
61 | * @param errorMsg error message
62 | */
63 | public ConnectionException(String errorMsg) {
64 | super();
65 | int index = findErrorMsg(errorMsg);
66 | if (index != -1) {
67 | this.errorMsg = errorMsg;
68 | }
69 | errorNo = ERROR_NO_SET[index];
70 | printEmptyException();
71 | }
72 |
73 | /**
74 | * Constructor.
75 | * @param errorNo error number
76 | * @param errorMsg error message
77 | */
78 | public ConnectionException(int errorNo, String errorMsg) {
79 | super();
80 | if (validateError(errorNo, errorMsg)) {
81 | this.errorNo = errorNo;
82 | this.errorMsg = errorMsg;
83 | }
84 | printEmptyException();
85 | }
86 |
87 | /**
88 | * Get error number.
89 | * @return error number
90 | */
91 | public int getErrorNo() {
92 | return errorNo;
93 | }
94 |
95 | /**
96 | * Set error number.
97 | * @param errorNo error number
98 | */
99 | public void setErrorno(int errorNo) {
100 | if (findErrorNo(errorNo) != -1) {
101 | this.errorNo = errorNo;
102 | }
103 | }
104 |
105 | /**
106 | * Get the error message.
107 | * @return error message
108 | */
109 | public String getErrorMsg() {
110 | return errorMsg;
111 | }
112 |
113 | /**
114 | * Set error message.
115 | * @param errorMsg error message
116 | */
117 | public void setErrormsg(String errorMsg) {
118 | if (findErrorMsg(errorMsg) != -1) {
119 | this.errorMsg = errorMsg;
120 | }
121 | }
122 |
123 | /**
124 | * Print Connection exception.
125 | */
126 | public void printEmptyException() {
127 | Log.e("Exception", "ConnectionException: [errorNo=" + errorNo
128 | + ", errorMsg=" + errorMsg);
129 | }
130 |
131 | /**
132 | * Fix the exception.
133 | * @param errorNo error number
134 | */
135 | public String fix(int errorNo) {
136 | StringBuilder errorMsg = new StringBuilder();
137 | switch (errorNo) {
138 | case 1:
139 | errorMsg.append("Exception: ").append(errorNo)
140 | .append("\nPlease check your internect connection.");
141 | break;
142 | default: break;
143 | }
144 | return errorMsg.toString();
145 | }
146 |
147 | /**
148 | * Find the corresponding error number index.
149 | * @param no error number
150 | * @return index
151 | */
152 | private int findErrorNo(int no) {
153 | for(int i = 0; i < ERROR_NO_SET.length; i++) {
154 | if (no == ERROR_NO_SET[i]) {
155 | return i;
156 | }
157 | }
158 | return -1;
159 | }
160 |
161 | /**
162 | * Find the corresponding error message index.
163 | * @param msg error message
164 | * @return index
165 | */
166 | private int findErrorMsg(String msg) {
167 | for (int i = 0; i < ERROR_MSG_SET.length; i++) {
168 | if (msg.equals(ERROR_MSG_SET[i])) {
169 | return i;
170 | }
171 | }
172 | return -1;
173 | }
174 |
175 | /**
176 | * Validate the error information.
177 | * @param no error number
178 | * @param msg error message
179 | * @return true if valid, false otherwise
180 | */
181 | private boolean validateError(int no, String msg) {
182 | for (int i = 0; i < ERROR_NO_SET.length; i++) {
183 | if (ERROR_NO_SET[i] == no && ERROR_MSG_SET[i].equals(msg)) {
184 | return true;
185 | }
186 | }
187 | return false;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/restaurantui/RestaurantActivity.java:
--------------------------------------------------------------------------------
1 | package foodeliver.restaurantui;
2 |
3 | import android.os.AsyncTask;
4 | import android.os.Bundle;
5 | import android.support.design.widget.FloatingActionButton;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.design.widget.TabLayout;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.FragmentManager;
10 | import android.support.v4.app.FragmentPagerAdapter;
11 | import android.support.v4.view.ViewPager;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.support.v7.widget.Toolbar;
14 | import android.view.Menu;
15 | import android.view.MenuItem;
16 | import android.view.View;
17 |
18 | import foodeliver.R;
19 | import foodeliver.entities.Restaurant;
20 | import foodeliver.exception.ConnectionException;
21 | import foodeliver.remote.Client;
22 |
23 | /**
24 | * Restaurant Activity.
25 | * @author Shuhui Yang
26 | */
27 | public class RestaurantActivity extends AppCompatActivity {
28 |
29 | /**
30 | * The {@link android.support.v4.view.PagerAdapter} that will provide
31 | * fragments for each of the sections. We use a
32 | * {@link FragmentPagerAdapter} derivative, which will keep every
33 | * loaded fragment in memory. If this becomes too memory intensive, it
34 | * may be best to switch to a
35 | * {@link android.support.v4.app.FragmentStatePagerAdapter}.
36 | */
37 | private SectionsPagerAdapter mSectionsPagerAdapter;
38 |
39 | private OrderFragment orderfragment;
40 | private RestaurantProfileFragment profilefragment;
41 | private MenuFragment menufragment;
42 |
43 | /**
44 | * restaurant info
45 | */
46 | private Restaurant restaurant = new Restaurant();
47 | String restaurantEmail = "";
48 |
49 | /**
50 | * The {@link ViewPager} that will host the section contents.
51 | */
52 | private ViewPager mViewPager;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.restaurantui_activity_restaurant);
58 |
59 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
60 | setSupportActionBar(toolbar);
61 | Bundle extras = getIntent().getExtras();
62 | if (extras != null) {
63 | restaurantEmail = extras.getString("restaurant_email");
64 | System.out.println("Restaurant Email: " + restaurantEmail);
65 | }
66 | // Create the adapter that will return a fragment for each of the three
67 | // primary sections of the activity.
68 | mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
69 |
70 | orderfragment = new OrderFragment();
71 | profilefragment = new RestaurantProfileFragment();
72 | menufragment = new MenuFragment();
73 |
74 | // Set up the ViewPager with the sections adapter.
75 | mViewPager = (ViewPager) findViewById(R.id.container);
76 | mViewPager.setAdapter(mSectionsPagerAdapter);
77 |
78 | TabLayout tabLayout = (TabLayout) findViewById(R.id.restaurant_tabs);
79 | tabLayout.setupWithViewPager(mViewPager);
80 |
81 | restaurant.readProfile(restaurantEmail);
82 | }
83 |
84 | public Restaurant getRestaurant(){ return this.restaurant; }
85 |
86 | @Override
87 | public boolean onCreateOptionsMenu(Menu menu) {
88 | // Inflate the menu; this adds items to the action bar if it is present.
89 | getMenuInflater().inflate(R.menu.menu_main, menu);
90 | return true;
91 | }
92 |
93 | @Override
94 | public boolean onOptionsItemSelected(MenuItem item) {
95 | // Handle action bar item clicks here. The action bar will
96 | // automatically handle clicks on the Home/Up button, so long
97 | // as you specify a parent activity in AndroidManifest.xml.
98 | int id = item.getItemId();
99 | //noinspection SimplifiableIfStatement
100 | if (id == R.id.action_settings) {
101 | return true;
102 | }
103 | return super.onOptionsItemSelected(item);
104 | }
105 |
106 | /**
107 | * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
108 | * one of the sections/tabs/pages.
109 | */
110 | public class SectionsPagerAdapter extends FragmentPagerAdapter {
111 | public SectionsPagerAdapter(FragmentManager fm) {
112 | super(fm);
113 | }
114 | @Override
115 | public Fragment getItem(int position) {
116 | // getItem is called to instantiate the fragment for the given page.
117 | if (position == 0){
118 | return orderfragment;
119 | } else if (position == 2){
120 | return profilefragment;
121 | } else {
122 | return menufragment;
123 | }
124 | }
125 |
126 | @Override
127 | public int getCount() {
128 | // Show 3 total pages.
129 | return 3;
130 | }
131 |
132 | @Override
133 | public CharSequence getPageTitle(int position) {
134 | switch (position) {
135 | case 0:
136 | return "ORDER MGMT";
137 | case 1:
138 | return "MENU MGMT";
139 | case 2:
140 | return "PROFILE";
141 | }
142 | return null;
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/Restaurant.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import java.util.ArrayList;
6 |
7 | import foodeliver.remote.DBTask;
8 | import foodeliver.remote.GetPicture;
9 | import foodeliver.utility.DataSearch;
10 | import foodeliver.utility.PictureSearch;
11 |
12 | /**
13 | * Restaurant Class.
14 | * @author Yu Qiu
15 | */
16 | public class Restaurant extends User implements DataSearch, PictureSearch {
17 |
18 | private String category; // Category
19 | private String location; // Location
20 | private String pictureURL; // Picture url
21 | private Bitmap picture; // Picture
22 | private String name; // Name
23 |
24 | private boolean toCreate;
25 |
26 | public Restaurant() {
27 | super();
28 | }
29 | public Restaurant(String email, String name, String category, String location, String picture) {
30 | this.email = email;
31 | this.name = name;
32 | this.category = category;
33 | this.location = location;
34 | this.pictureURL = picture;
35 | }
36 |
37 | // Getter and Setter
38 | public String getName() {
39 | return name;
40 | }
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 | public String getCategory() {
45 | return category;
46 | }
47 | public void setCategory(String category) {
48 | this.category = category;
49 | }
50 | public String getLocation() {
51 | return location;
52 | }
53 | public void setLocation(String location) { this.location = location; }
54 | public String getPictureURL() { return pictureURL; }
55 | public void setPictureRUL(String pictureURL) { this.pictureURL = pictureURL; }
56 | public Bitmap getPicture() {
57 | return picture;
58 | }
59 | public void setPicture(Bitmap picture) {
60 | this.picture = picture;
61 | }
62 |
63 | // Profile Manipulation Functions
64 | @Override
65 | public void createProfile(String[] params) {
66 | // params: Email, Name, Phone, Password, CardNumber, Address, Category, Location, Picture
67 | String sql = "INSERT INTO RESTAURANT VALUES ('" + params[0] + "','"
68 | + params[1] + "','" + params[2] + "','" + params[3] + "','"
69 | + params[4] + "','" + params[5] + "','" + params[6] + "','"
70 | + params[7] + "','" + params[8] + "')";
71 | toCreate = true;
72 | DBTask dbT = new DBTask();
73 | ArrayList list = new ArrayList();
74 | list.add(sql);
75 | dbT.getResult(list, this, "update");
76 | }
77 |
78 | @Override
79 | public void readProfile(String email) {
80 | this.setEmail(email);
81 | String sql = "SELECT * FROM RESTAURANT WHERE Email='" + email + "';";
82 | DBTask dbT = new DBTask();
83 | ArrayList list = new ArrayList();
84 | list.add(sql);
85 | dbT.getResult(list, Restaurant.this, "result");
86 | }
87 |
88 | @Override
89 | public void updateProfile(String[] params) {
90 | // params: Email, Name, Phone, Password, CardNumber, Address, Category, Location, Picture
91 | String sql = "UPDATE RESTAURANT SET Name='" + params[1] + "', Phone='" + params[2]
92 | + "', Password='" + params[3] + "', CardNumber='" + params[4]
93 | + "', Address='" + params[5] + "', Category='" + params[6]
94 | + "', Location='" + params[7] + "', Picture='" + params[8]
95 | + "' WHERE Email='" + params[0] + "';";
96 | toCreate = false;
97 | DBTask dbT = new DBTask();
98 | ArrayList list = new ArrayList();
99 | list.add(sql);
100 | dbT.getResult(list, this, "update");
101 | }
102 |
103 | @Override
104 | public void dbResultReady(String result) {
105 | System.out.println("SQL Result: " + result);
106 | String[] elements = result.split("\t");
107 | this.setPassword(elements[3]);
108 | this.setName(elements[1]);
109 | this.setAddress(elements[5]);
110 | this.setPhone(elements[2]);
111 | this.setCategory(elements[6]);
112 | this.setLocation(elements[7]);
113 | this.setCard(elements[4]);
114 | this.setPictureRUL(elements[8]);
115 | GetPicture gp = new GetPicture();
116 | ArrayList searchPics = new ArrayList<>();
117 | searchPics.add(elements[8]);
118 | gp.search(searchPics, Restaurant.this);
119 | }
120 |
121 | @Override
122 | public void updateReady(String result) {
123 | if (result.equals("true")) {
124 | if (toCreate) {
125 | transition.setToast("New profile created.");
126 | transition.transit();
127 | } else {
128 | showToast.setToast("New profile saved successfully.");
129 | }
130 | } else {
131 | if (toCreate) {
132 | transition.setToast("Sorry, the account already exists.");
133 | } else {
134 | showToast.setToast("Sorry, save failed.");
135 | }
136 | }
137 | }
138 |
139 | @Override
140 | public void deleteProfile(String email) {}
141 | @Override
142 | public void dbDetailReady(String result) {}
143 | @Override
144 | public void deleteReady(String result) {}
145 | @Override
146 | public void pictureReady(ArrayList pictures) {
147 | this.setPicture(pictures.get(0));
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/FooDelivery_client/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FooDelivery
3 | Settings
4 | Hello World from section: %1$d
5 |
6 |
7 | Email
8 | Password (optional)
9 | Sign in As Customer
10 | Sign in As Restaurant
11 | Create Customer Account Now
12 | Create Restaurant Account Now
13 | Sign in
14 | This email address is invalid
15 | This password is too short
16 | This password is incorrect
17 | This field is required
18 | "Contacts permissions are needed for providing email
19 | completions."
20 |
21 | Create a Customer Account
22 | Create a Restaurant Account
23 | E-mail:
24 | Password:
25 | Confirm Password:
26 | Card:
27 | Address:
28 | Submit
29 | Restaurant Name:
30 | Phone Number:
31 | Location:
32 | Category:
33 | LoginActivity
34 | RestaurantRegisterActivity
35 | CustomerRegisterActivity
36 | RestaurantActivity
37 |
38 | My Orders
39 | Order
40 | Restaurant
41 | Status
42 |
43 |
44 | Little Asia
45 | Address: 301 South Craig Street #2
46 | Contact: (412) 622-0133
47 |
48 | ID
49 | Name
50 | Picture
51 | Price
52 | Quantity
53 | Date
54 |
55 | Menu
56 | Price
57 | Name
58 | Picture
59 |
60 | Customer Profile
61 |
62 | Cancel
63 | Confirm
64 |
65 | Search
66 | Category
67 | Location
68 |
69 | Restaurant Details
70 | Profile Details
71 |
72 | Add
73 | Update
74 | Delete
75 | Edit
76 | Save
77 | PlaceOrderActivity
78 |
79 |
80 | - All
81 | - ShadySide
82 | - Squirrel Hill
83 | - North Oakland
84 | - South Oakland
85 |
86 |
87 |
88 | - ShadySide
89 | - Squirrel Hill
90 | - North Oakland
91 | - South Oakland
92 |
93 |
94 |
95 | - All
96 | - American
97 | - Chinese
98 | - Indian
99 | - Mexican
100 | - Japanese
101 | - Korean
102 | - Franch
103 |
104 |
105 |
106 | - American
107 | - Chinese
108 | - Indian
109 | - Mexican
110 | - Japanese
111 | - Korean
112 | - Franch
113 |
114 |
115 |
116 | - Online
117 | - Offline
118 |
119 |
120 |
121 | - 0
122 | - 1
123 | - 2
124 | - 3
125 | - 4
126 | - 5
127 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/customerui/CustomerProfileFragment.java:
--------------------------------------------------------------------------------
1 | package foodeliver.customerui;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.Button;
9 | import android.widget.EditText;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import foodeliver.R;
14 | import foodeliver.entities.Customer;
15 | import foodeliver.utility.ShowToast;
16 |
17 |
18 | /**
19 | * A simple {@link Fragment} subclass.
20 | * Use the {@link CustomerProfileFragment#newInstance} factory method to
21 | * create an instance of this fragment.
22 | * @author Jiaqi Zhang
23 | */
24 | public class CustomerProfileFragment extends Fragment implements ShowToast {
25 |
26 | private Customer customer;
27 | private TextView emailText;
28 | private EditText passwordText;
29 | private EditText cPasswordText;
30 | private EditText phoneText;
31 | private EditText cardText;
32 | private EditText addrText;
33 |
34 | public CustomerProfileFragment() {
35 | // Required empty public constructor
36 | }
37 |
38 | /**
39 | * Use this factory method to create a new instance of
40 | * this fragment using the provided parameters.
41 | *
42 | * @return A new instance of fragment CustomerProfileFragment.
43 | */
44 | public static CustomerProfileFragment newInstance() {
45 | CustomerProfileFragment fragment = new CustomerProfileFragment();
46 | Bundle args = new Bundle();
47 | fragment.setArguments(args);
48 | return fragment;
49 | }
50 |
51 | @Override
52 | public void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | }
55 |
56 | @Override
57 | public void onActivityCreated(Bundle savedInstanceState) {
58 | super.onActivityCreated(savedInstanceState);
59 |
60 | CustomerActivity cActivity = (CustomerActivity) getActivity();
61 | customer = cActivity.getCustomer();
62 | }
63 |
64 | @Override
65 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
66 | Bundle savedInstanceState) {
67 | // Inflate the layout for this fragment
68 | View view = inflater.inflate(R.layout.customerui_fragment_profile, container, false);
69 | Button editProfile = (Button) view.findViewById(R.id.customer_edit_button);
70 | CustomerActivity cActivity = (CustomerActivity) getActivity();
71 |
72 | customer = cActivity.getCustomer();
73 | emailText = (TextView) view.findViewById(R.id.register_email_text);
74 | passwordText = (EditText) view.findViewById(R.id.register_password_text);
75 | cPasswordText = (EditText) view.findViewById(R.id.register_confirm_password_text);
76 | cardText = (EditText) view.findViewById(R.id.register_card_text);
77 | addrText = (EditText) view.findViewById(R.id.register_address_text);
78 | phoneText = (EditText) view.findViewById(R.id.register_phone_text);
79 |
80 | emailText.setText(customer.getEmail());
81 | phoneText.setText(customer.getPhone());
82 | passwordText.setText(customer.getPassword());
83 | cPasswordText.setText(customer.getPassword());
84 | cardText.setText(customer.getCard());
85 | addrText.setText(customer.getAddress());
86 |
87 | passwordText.setEnabled(false);
88 | cPasswordText.setEnabled(false);
89 | cardText.setEnabled(false);
90 | addrText.setEnabled(false);
91 | phoneText.setEnabled(false);
92 |
93 | editProfile.setOnClickListener(new View.OnClickListener() {
94 | @Override
95 | public void onClick(View view) {
96 | // enable edit customer profile
97 | passwordText.setEnabled(true);
98 | cPasswordText.setEnabled(true);
99 | cardText.setEnabled(true);
100 | addrText.setEnabled(true);
101 | phoneText.setEnabled(true);
102 | }
103 | });
104 |
105 | Button saveProfile = (Button) view.findViewById(R.id.customer_save_button);
106 | saveProfile.setOnClickListener(new View.OnClickListener() {
107 | @Override
108 | public void onClick(View view) {
109 | // save customer profile
110 | if (!passwordText.getText().toString().trim().
111 | equals(cPasswordText.getText().toString().trim())) {
112 | setToast("Confirmed password is not consistent.");
113 | passwordText.setText(customer.getPassword());
114 | cPasswordText.setText(customer.getPassword());
115 | } else {
116 | String[] params = new String[4];
117 | params[0] = phoneText.getText().toString().trim();
118 | params[1] = passwordText.getText().toString().trim();
119 | params[2] = cardText.getText().toString().trim();
120 | params[3] = addrText.getText().toString().trim();
121 | customer.setShowToast(CustomerProfileFragment.this);
122 | customer.updateProfile(params);
123 | }
124 | passwordText.setEnabled(false);
125 | cPasswordText.setEnabled(false);
126 | cardText.setEnabled(false);
127 | addrText.setEnabled(false);
128 | phoneText.setEnabled(false);
129 | }
130 | });
131 | return view;
132 | }
133 |
134 | @Override
135 | public void setToast(String str) {
136 | Toast.makeText(getActivity(),
137 | str, Toast.LENGTH_LONG).show();
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_fragment_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
22 |
23 |
33 |
34 |
44 |
45 |
56 |
57 |
68 |
69 |
77 |
78 |
88 |
89 |
97 |
98 |
108 |
109 |
119 |
120 |
130 |
131 |
141 |
142 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/customerui/CustomerActivity.java:
--------------------------------------------------------------------------------
1 | package foodeliver.customerui;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.TabLayout;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentManager;
7 | import android.support.v4.app.FragmentPagerAdapter;
8 | import android.support.v4.view.ViewPager;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 |
14 | import foodeliver.R;
15 | import foodeliver.entities.Customer;
16 |
17 | /**
18 | * Customer Activity.
19 | * @author Jiaqi Zhang
20 | */
21 | public class CustomerActivity extends AppCompatActivity {
22 |
23 | /**
24 | * The {@link android.support.v4.view.PagerAdapter} that will provide
25 | * fragments for each of the sections. We use a
26 | * {@link FragmentPagerAdapter} derivative, which will keep every
27 | * loaded fragment in memory. If this becomes too memory intensive, it
28 | * may be best to switch to a
29 | * {@link android.support.v4.app.FragmentStatePagerAdapter}.
30 | */
31 | private SectionsPagerAdapter mSectionsPagerAdapter;
32 |
33 | /**
34 | * The {@link ViewPager} that will host the section contents.
35 | */
36 | private ViewPager mViewPager;
37 |
38 | // Search Fragment
39 | private SearchFragment searchFragment;
40 |
41 | private MyorderFragment myorderFragment;
42 |
43 | private CustomerProfileFragment customerProfileFragment;
44 | // Fragment Manager
45 | private FragmentManager fragmentManager;
46 |
47 | private Customer customer;
48 |
49 | private String initialLoc = "";
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.customerui_activity_customer);
55 |
56 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
57 | setSupportActionBar(toolbar);
58 | customer = new Customer();
59 | Bundle extras = getIntent().getExtras();
60 | if (extras != null) {
61 | customer.setEmail(extras.getString("customer_email"));
62 | System.out.println("Customer Email: " + customer.getEmail());
63 | initialLoc = extras.getString("location");
64 | System.out.println("Initial Location: " + initialLoc);
65 | }
66 | // Create the adapter that will return a fragment for each of the three
67 | // primary sections of the activity.
68 | fragmentManager = getSupportFragmentManager();
69 | mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);
70 |
71 | searchFragment = new SearchFragment();
72 | myorderFragment = new MyorderFragment();
73 | customerProfileFragment = new CustomerProfileFragment();
74 |
75 | // Set up the ViewPager with the sections adapter.
76 | mViewPager = (ViewPager) findViewById(R.id.container);
77 | mViewPager.setAdapter(mSectionsPagerAdapter);
78 |
79 | TabLayout tabLayout = (TabLayout) findViewById(R.id.customer_tabs);
80 | tabLayout.setupWithViewPager(mViewPager);
81 |
82 | customer.readProfile(customer.getEmail());
83 | }
84 |
85 | @Override
86 | public boolean onCreateOptionsMenu(Menu menu) {
87 | // Inflate the menu; this adds items to the action bar if it is present.
88 | getMenuInflater().inflate(R.menu.menu_main, menu);
89 | return true;
90 | }
91 |
92 | @Override
93 | public boolean onOptionsItemSelected(MenuItem item) {
94 | // Handle action bar item clicks here. The action bar will
95 | // automatically handle clicks on the Home/Up button, so long
96 | // as you specify a parent activity in AndroidManifest.xml.
97 | int id = item.getItemId();
98 |
99 | //noinspection SimplifiableIfStatement
100 | if (id == R.id.action_settings) {
101 | return true;
102 | }
103 |
104 | return super.onOptionsItemSelected(item);
105 | }
106 |
107 | public String getCustomerEmail() {
108 | return customer.getEmail();
109 | }
110 |
111 | public String getCustomerPhone() {
112 | return customer.getPhone();
113 | }
114 |
115 | public String getCustomerAddr() {
116 | return customer.getAddress();
117 | }
118 |
119 | public String getPassword() {
120 | return customer.getPassword();
121 | }
122 |
123 | public String getCard() {
124 | return customer.getCard();
125 | }
126 |
127 | public Customer getCustomer() {
128 | return customer;
129 | }
130 |
131 | public String getInitialLoc() {
132 | return initialLoc;
133 | }
134 |
135 | /**
136 | * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
137 | * one of the sections/tabs/pages.
138 | */
139 | public class SectionsPagerAdapter extends FragmentPagerAdapter {
140 |
141 | public SectionsPagerAdapter(FragmentManager fm) {
142 | super(fm);
143 | }
144 |
145 | @Override
146 | public Fragment getItem(int position) {
147 | // getItem is called to instantiate the fragment for the given page.
148 | if (position == 0) {
149 | return searchFragment;
150 | } else if (position == 1) {
151 | return myorderFragment;
152 | } else {
153 | return customerProfileFragment;
154 | }
155 | }
156 |
157 | @Override
158 | public int getCount() {
159 | // Show 3 total pages.
160 | return 3;
161 | }
162 |
163 | @Override
164 | public CharSequence getPageTitle(int position) {
165 | switch (position) {
166 | case 0:
167 | return "SEARCH RESTAURANT";
168 | case 1:
169 | return "MY ORDERS";
170 | case 2:
171 | return "MY PROFILE";
172 | }
173 | return null;
174 | }
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/login_content_customer_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
24 |
25 |
34 |
42 |
43 |
52 |
60 |
61 |
70 |
78 |
79 |
88 |
97 |
98 |
107 |
108 |
116 |
117 |
126 |
127 |
136 |
137 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/remote/Client.java:
--------------------------------------------------------------------------------
1 | package foodeliver.remote;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 | import java.net.HttpURLConnection;
7 | import java.net.MalformedURLException;
8 | import java.net.URL;
9 | import java.util.HashMap;
10 |
11 | import foodeliver.exception.ConnectionException;
12 |
13 | /**
14 | * Remote Client Class.
15 | * @author Shuhui Yang
16 | */
17 | public class Client {
18 |
19 | // Server URL
20 | private static String SERVER_URL = "10.0.2.2:8080/FooDelivery/ServerServlet";
21 |
22 | /**
23 | * Send request to create data record.
24 | * @return true if success, false otherwise
25 | * @throws ConnectionException connection exception
26 | */
27 | public static String createData(String sql) throws ConnectionException {
28 | sql = sql.replaceAll(" ", "%20");
29 | sql = sql.replaceAll("'", "%27");
30 | String url = "http://" + SERVER_URL + "?sql=" + sql + "&method=create";
31 | URL requestUrl = null;
32 | HttpURLConnection con = null;
33 | try {
34 | requestUrl = new URL(url);
35 | con = (HttpURLConnection) requestUrl.openConnection();
36 | // if create successful
37 | if (con.getResponseCode() == 200){
38 | // retrieve response and judge
39 | BufferedReader read = new BufferedReader(new InputStreamReader(con.getInputStream()));
40 | String input = read.readLine().trim();
41 | if (input.equals("False")) {
42 | return "false";
43 | }
44 | return "true";
45 | } else {
46 | throw new ConnectionException(1);
47 | }
48 | } catch (MalformedURLException e) {
49 | e.printStackTrace();
50 | } catch (IOException e) {
51 | e.printStackTrace();
52 | }
53 | return "false";
54 | }
55 |
56 | /**
57 | * Send request to read data record.
58 | * @return true if success, false otherwise
59 | * @throws ConnectionException connection exception
60 | */
61 | public static String readData(String sql) throws ConnectionException {
62 | sql = sql.replaceAll(" ", "%20");
63 | String url = "http://" + SERVER_URL + "?sql=" + sql + "&method=read";
64 | URL requestUrl = null;
65 | HttpURLConnection con = null;
66 | StringBuilder sb = new StringBuilder();
67 | try {
68 | requestUrl = new URL(url);
69 | con = (HttpURLConnection) requestUrl.openConnection();
70 | // if create successful
71 | if (con.getResponseCode() == 200){
72 | // retrieve response
73 | BufferedReader read = new BufferedReader(new InputStreamReader(con.getInputStream()));
74 | String input = null;
75 | while ((input = read.readLine()) != null){
76 | sb.append(input).append("\n");
77 | }
78 | } else {
79 | throw new ConnectionException(1);
80 | }
81 | } catch (MalformedURLException e) {
82 | e.printStackTrace();
83 | } catch (IOException e) {
84 | e.printStackTrace();
85 | }
86 | return sb.toString();
87 | }
88 |
89 | /**
90 | * Update data.
91 | * @param tablename table name
92 | * @param values values
93 | * @return true if success, false otherwise
94 | * @throws ConnectionException connection exception
95 | */
96 | public static boolean updateData(String tablename, HashMap values)
97 | throws ConnectionException {
98 | // form parameter including tablename and values
99 | StringBuilder parameter = new StringBuilder();
100 | parameter.append("tablename").append("=").append(tablename);
101 | for (String key: values.keySet()){
102 | parameter.append("&").append(key).append("=").append(values.get(key));
103 | }
104 | parameter.append("&").append("method").append("=").append("update");
105 | // form GET request url and open connection
106 | String url = "http://" + SERVER_URL + "?" + parameter.toString();
107 | URL requestUrl = null;
108 | HttpURLConnection con = null;
109 | try {
110 | requestUrl = new URL(url);
111 | con = (HttpURLConnection) requestUrl.openConnection();
112 | // if create successful
113 | if (con.getResponseCode() == 200){
114 | // retrieve response and judge
115 | return true;
116 | } else {
117 | throw new ConnectionException(1);
118 | }
119 | } catch (MalformedURLException e) {
120 | e.printStackTrace();
121 | } catch (IOException e) {
122 | e.printStackTrace();
123 | }
124 | return false;
125 | }
126 |
127 | /**
128 | * Delete data from the database.
129 | * @param tablename table name
130 | * @param conditions conditions
131 | * @return true if success, false otherwise
132 | * @throws ConnectionException connection exception
133 | */
134 | public static boolean deleteData(String tablename, HashMap conditions)
135 | throws ConnectionException {
136 | // form parameter including tablename and values
137 | StringBuilder parameter = new StringBuilder();
138 | parameter.append("tablename").append("=").append(tablename);
139 | for (String key: conditions.keySet()){
140 | parameter.append("&").append(key).append("=").append(conditions.get(key));
141 | }
142 | parameter.append("&").append("method").append("=").append("delete");
143 | // form GET request url and open connection
144 | String url = "http://" + SERVER_URL + "?" + parameter.toString();
145 | URL requestUrl = null;
146 | HttpURLConnection con = null;
147 | try {
148 | requestUrl = new URL(url);
149 | con = (HttpURLConnection) requestUrl.openConnection();
150 | // if create successful
151 | if (con.getResponseCode() == 200){
152 | // retrieve response and judge
153 | return true;
154 | } else {
155 | throw new ConnectionException(1);
156 | }
157 | } catch (MalformedURLException e) {
158 | e.printStackTrace();
159 | } catch (IOException e) {
160 | e.printStackTrace();
161 | }
162 | return false;
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_fragment_profile.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
16 |
17 |
27 |
28 |
38 |
39 |
49 |
50 |
61 |
62 |
72 |
73 |
84 |
85 |
95 |
96 |
107 |
108 |
118 |
119 |
129 |
130 |
140 |
141 |
151 |
152 |
164 |
165 |
177 |
178 |
179 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/customerui_content_place_order.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
24 |
25 |
34 |
35 |
44 |
45 |
56 |
57 |
67 |
68 |
78 |
79 |
89 |
90 |
100 |
101 |
108 |
109 |
119 |
120 |
130 |
131 |
138 |
139 |
150 |
151 |
159 |
160 |
170 |
171 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/entities/FoodOrder.java:
--------------------------------------------------------------------------------
1 | package foodeliver.entities;
2 |
3 | import java.util.ArrayList;
4 |
5 | import foodeliver.utility.DataSearch;
6 | import foodeliver.remote.DBTask;
7 | import foodeliver.utility.Transition;
8 |
9 | /**
10 | * Food Order class.
11 | * @author Yu Qiu
12 | */
13 | public class FoodOrder extends Order implements DataSearch {
14 |
15 | private String restaurant;
16 |
17 | // customer used fields
18 | private Transition transition;
19 | private boolean toCreate = false;
20 |
21 | // restaurant used fields
22 | private String customerPhone;
23 | private String customerAddress;
24 | private boolean customerFlag = true;
25 |
26 | public FoodOrder(){}
27 | public FoodOrder(String orderId, String name, String status, String price, String date, String customerPhone, String customerAddress){
28 | this.orderId = orderId;
29 | this.restaurant = name;
30 | this.status = status;
31 | this.price = Double.parseDouble(price);
32 | this.timestamp = date;
33 | this.customerPhone = customerPhone;
34 | this.customerAddress = customerAddress;
35 | items = new ArrayList<>();
36 | }
37 |
38 | @Override
39 | public void createOrder(String customerEmail, String restaurantEmail, String orderTime,
40 | String phone, String addr, String payment, double totalPrice, ArrayList items) {
41 | this.orderId = customerEmail + restaurantEmail + orderTime;
42 | this.status = "Pending";
43 | this.timestamp = orderTime;
44 | this.price = totalPrice;
45 | toCreate = true;
46 |
47 | ArrayList sqls = new ArrayList();
48 | StringBuilder sb = new StringBuilder();
49 | sb.append("INSERT INTO ORDERTABLE VALUES(");
50 | sb.append("'").append(orderId).append("', ");
51 | sb.append("'").append(customerEmail).append("', ");
52 | sb.append("'").append(restaurantEmail).append("', ");
53 | sb.append("'").append(orderTime).append("', ");
54 | sb.append("'").append(phone).append("', ");
55 | sb.append("'").append(addr).append("', ");
56 | sb.append("'").append(payment).append("', ");
57 | sb.append("'").append(totalPrice).append("', ");
58 | sb.append("'").append(status).append("');");
59 | sqls.add(sb.toString());
60 | for (Food item : items) {
61 | if (item.getQuantity() > 0) {
62 | sb = new StringBuilder();
63 | sb.append("INSERT INTO ORDERITEM VALUES(");
64 | sb.append("'").append(orderId).append("', ");
65 | sb.append("'").append(item.getId()).append("', ");
66 | sb.append("'").append(item.getQuantity()).append("');");
67 | item.setQuantity(0);
68 | sqls.add(sb.toString());
69 | }
70 | }
71 | DBTask dbT = new DBTask();
72 | dbT.getResult(sqls, this, "update");
73 | }
74 |
75 | @Override
76 | public void readOrder() {
77 | DBTask dbT = new DBTask();
78 | ArrayList list = new ArrayList();
79 | list.add("SELECT m.FoodId, m.FoodName, m.FoodPrice, oi.Quantity" +
80 | " FROM ORDERITEM oi, MENU m WHERE oi.OrderId='"
81 | + orderId + "' AND oi.FoodId=m.FoodId;");
82 | dbT.getResult(list, this, "detail");
83 | }
84 |
85 | @Override
86 | public void updateOrder(String orderId, String name, String status, String p) {
87 | this.orderId = orderId;
88 | this.restaurant = name;
89 | this.status = status;
90 | this.price = Double.parseDouble(p);
91 | toCreate = false;
92 | }
93 |
94 | @Override
95 | public void deleteOrder(String orderNumber) {
96 | }
97 |
98 | @Override
99 | public void showOrderDetails() {
100 | System.out.println(customerFlag);
101 | if (customerFlag){
102 | StringBuilder show = new StringBuilder();
103 | for (Food f : items) {
104 | show.append("Item: ").append(f.getName()).append(",\tPrice: ").append(f.getPrice())
105 | .append(",\tQuantity: ").append(f.getQuantity()).append("\n");
106 | System.out.println(show.toString());
107 | }
108 | showToast.setToast(show.toString());
109 | } else {
110 | StringBuilder show = new StringBuilder();
111 | for (Food f: items) {
112 | show.append("Item: ").append(f.getName()).append(", \tPrice: ").append(f.getPrice())
113 | .append(", \tQuantity: ").append(f.getQuantity()).append("\n");
114 | }
115 | show.append("Delivary Address: ").append(this.getCustomerAddress()).append("\n");
116 | show.append("Customer Phone: ").append(this.getCustomerPhone());
117 | showToast.setToast(show.toString());
118 | }
119 | }
120 |
121 | @Override
122 | public void dbResultReady(String sqlResult) {
123 | }
124 |
125 | @Override
126 | public void updateReady(String result) {
127 | if (result.equals("true")) {
128 | if (toCreate) {
129 | transition.setToast("Order Placed.");
130 | transition.transit();
131 | } else {
132 | showToast.setToast("Order updated successfully.");
133 | }
134 | } else {
135 | if (toCreate) {
136 | transition.setToast("Sorry, operation failed.");
137 | } else {
138 | showToast.setToast("Sorry, operation failed.");
139 | }
140 | }
141 | }
142 |
143 | @Override
144 | public void dbDetailReady(String sqlResult) {
145 | String[] results = sqlResult.split("\n");
146 | StringBuilder show = new StringBuilder();
147 | for (String result : results) {
148 | String[] elements = result.split("\t");
149 | if (elements.length > 3) {
150 | Food food = new Food(elements[0], elements[1], elements[2], Integer.parseInt(elements[3]));
151 | System.out.println(food.getQuantity());
152 | items.add(food);
153 | }
154 | }
155 | }
156 |
157 | public boolean isCustomerFlag() {
158 | return customerFlag;
159 | }
160 |
161 | public void setCustomerFlag(boolean customerFlag) {
162 | this.customerFlag = customerFlag;
163 | }
164 |
165 | public void setRestaurant(String restaurant) {
166 | this.restaurant = restaurant;
167 | }
168 |
169 | public String getCustomerPhone() {
170 | return customerPhone;
171 | }
172 |
173 | public void setCustomerPhone(String customerPhone) {
174 | this.customerPhone = customerPhone;
175 | }
176 |
177 | public String getCustomerAddress() {
178 | return customerAddress;
179 | }
180 |
181 | public void setCustomerAddress(String customerAddress) {
182 | this.customerAddress = customerAddress;
183 | }
184 |
185 | public void setTransition(Transition transition) {
186 | this.transition = transition;
187 | }
188 |
189 | @Override
190 | public void deleteReady(String result) {
191 |
192 | }
193 |
194 | public String getRestaurant() {
195 | return restaurant;
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/res/layout/restaurantui_fragment_menu.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
12 |
13 |
24 |
25 |
36 |
37 |
48 |
49 |
60 |
61 |
62 |
63 |
70 |
71 |
80 |
81 |
82 |
83 |
88 |
89 |
94 |
95 |
105 |
106 |
110 |
111 |
112 |
117 |
118 |
129 |
130 |
135 |
136 |
137 |
142 |
143 |
154 |
155 |
160 |
161 |
162 |
163 |
170 |
171 |
179 |
180 |
188 |
189 |
190 |
191 |
192 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/login/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package foodeliver.login;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.location.Location;
7 | import android.location.LocationListener;
8 | import android.location.LocationManager;
9 | import android.os.AsyncTask;
10 | import android.os.Bundle;
11 | import android.support.v4.app.ActivityCompat;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.support.v7.widget.Toolbar;
14 | import android.view.View;
15 | import android.widget.Button;
16 | import android.widget.EditText;
17 | import android.widget.Toast;
18 |
19 | import foodeliver.R;
20 | import foodeliver.customerui.CustomerActivity;
21 | import foodeliver.exception.ConnectionException;
22 | import foodeliver.remote.Client;
23 | import foodeliver.restaurantui.RestaurantActivity;
24 |
25 | /**
26 | * Log in Activity.
27 | * @author Yu Qiu
28 | */
29 | public class LoginActivity extends AppCompatActivity {
30 |
31 | EditText emailTextView;
32 | EditText passwordTextView;
33 | LocationManager locationManager;
34 | Location location;
35 | private static final double shadysideLatitude = 40.4556477;
36 | private static final double shadysideLongitude = -79.9276651;
37 | private static final double squirrelHillLatitude = 40.4381246;
38 | private static final double squirrelHillLongitude = -79.9192175;
39 | private static final double northOaklandLatitude = 40.4466296;
40 | private static final double northOaklandLongitude = -79.9542438;
41 | private static final double southOaklandLatitude = 40.4319875;
42 | private static final double southOaklandLongitude = -79.9598383;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) throws SecurityException {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.login_activity_login);
48 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
49 | setSupportActionBar(toolbar);
50 |
51 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
52 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS},1);
53 | CustomLocationListener test = new CustomLocationListener();
54 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
55 | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, test);
56 | location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
57 |
58 | Button loginCustomerButton = (Button) findViewById(R.id.email_sign_in_customer_button);
59 | Button loginRestaurantButton = (Button) findViewById(R.id.email_sign_in_restaurant_button);
60 | Button customerReg = (Button) findViewById(R.id.email_register_customer_button);
61 | Button restaurantReg = (Button) findViewById(R.id.email_register_restaurant_button);
62 |
63 | emailTextView = (EditText)findViewById(R.id.email);
64 | passwordTextView = (EditText)findViewById(R.id.password);
65 |
66 | loginCustomerButton.setOnClickListener(new View.OnClickListener() {
67 | @Override
68 | public void onClick(View view) {
69 | String sql = "SELECT password FROM CONSUMER WHERE Email = '" + emailTextView.getText().toString() + "'";
70 | new GetPassword().execute(sql + ":Consumer");
71 | }
72 | });
73 |
74 | loginRestaurantButton.setOnClickListener(new View.OnClickListener() {
75 | @Override
76 | public void onClick(View view) {
77 | String sql = "SELECT password FROM RESTAURANT WHERE Email = '" + emailTextView.getText().toString() + "'";
78 | new GetPassword().execute(sql + ":Restaurant");
79 | }
80 | });
81 |
82 | customerReg.setOnClickListener(new View.OnClickListener() {
83 | @Override
84 | public void onClick(View view) {
85 | Intent intent = new Intent(getApplicationContext(), CustomerRegisterActivity.class);
86 | startActivity(intent);
87 | }
88 | });
89 |
90 | restaurantReg.setOnClickListener(new View.OnClickListener() {
91 | @Override
92 | public void onClick(View view) {
93 | Intent intent = new Intent(getApplicationContext(), RestaurantRegisterActivity.class);
94 | startActivity(intent);
95 | }
96 | });
97 | }
98 |
99 | private class GetPassword extends AsyncTask {
100 | protected String doInBackground(String... sql) {
101 | return search(sql[0]);
102 | }
103 | protected void onPostExecute(String sql) throws SecurityException {
104 | String[] results = sql.split(":");
105 | if (results[0].trim().equals(passwordTextView.getText().toString())) {
106 | if (results[1].trim().equals("Restaurant")) {
107 | Intent intent = new Intent(getApplicationContext(), RestaurantActivity.class);
108 | intent.putExtra("restaurant_email", emailTextView.getText().toString());
109 | startActivity(intent);
110 | } else {
111 | Intent intent = new Intent(getApplicationContext(), CustomerActivity.class);
112 | intent.putExtra("customer_email", emailTextView.getText().toString());
113 | intent.putExtra("location", getLocation());
114 | startActivity(intent);
115 | }
116 | } else {
117 | Toast.makeText(LoginActivity.this,
118 | "Sorry, we could not find an account for this email address.", Toast.LENGTH_LONG).show();
119 | }
120 | }
121 | private String search(String sql) {
122 | String[] sqls = sql.split(":");
123 | String results = "";
124 | try {
125 | results = Client.readData(sqls[0]);
126 | } catch (ConnectionException e) {
127 | e.printStackTrace();
128 | }
129 | return results + ":" + sqls[1];
130 | }
131 | }
132 |
133 | public class CustomLocationListener implements LocationListener {
134 | @Override
135 | public void onLocationChanged(Location location) {}
136 | @Override
137 | public void onProviderDisabled(String provider) {}
138 | @Override
139 | public void onProviderEnabled(String provider) {}
140 | @Override
141 | public void onStatusChanged(String provider, int status, Bundle extras) {}
142 | }
143 |
144 | public String getLocation() {
145 | double latitude = location.getLatitude();
146 | double longitude = location.getLongitude();
147 | String[] location = {"ShadySide", "Squirrel Hill", "North Oakland", "South Oakland"};
148 | double[] distance = new double[4];
149 | distance[0] = Math.pow((latitude - shadysideLatitude), 2) + Math.pow((longitude - shadysideLongitude), 2);
150 | distance[1] = Math.pow((latitude - squirrelHillLatitude), 2) + Math.pow((longitude - squirrelHillLongitude), 2);
151 | distance[2] = Math.pow((latitude - northOaklandLatitude), 2) + Math.pow((longitude - northOaklandLongitude), 2);
152 | distance[3] = Math.pow((latitude - southOaklandLatitude), 2) + Math.pow((longitude - southOaklandLongitude), 2);
153 | int choice = 0;
154 | double minDistance = distance[0];
155 | for (int i = 1; i < 4; i++) {
156 | if (distance[i] < minDistance) {
157 | choice = i;
158 | }
159 | }
160 | return location[choice];
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/restaurantui/RestaurantProfileFragment.java:
--------------------------------------------------------------------------------
1 | package foodeliver.restaurantui;
2 |
3 | import android.os.AsyncTask;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | import foodeliver.R;
16 | import foodeliver.customerui.CustomerActivity;
17 | import foodeliver.entities.Restaurant;
18 | import foodeliver.exception.ConnectionException;
19 | import foodeliver.remote.Client;
20 | import foodeliver.utility.ShowToast;
21 |
22 | /**
23 | * Restaurant Profile Fragment.
24 | * @author Shuhui Yang
25 | */
26 | public class RestaurantProfileFragment extends Fragment implements ShowToast{
27 |
28 | private Restaurant restaurant;
29 |
30 | private EditText passwordText;
31 | private EditText categoryText;
32 | private EditText phoneText;
33 | private EditText cardText;
34 | private EditText addressText;
35 | private EditText locationText;
36 | private EditText pictureURLText;
37 |
38 | private TextView nameTextView;
39 | private TextView accountTextView;
40 |
41 | private ImageView picture;
42 |
43 | public RestaurantProfileFragment() {
44 | // Required empty public constructor
45 | }
46 |
47 | /**
48 | * Use this factory method to create a new instance of
49 | * this fragment using the provided parameters.
50 | *
51 | * @return A new instance of fragment RestaurantProfileFragment.
52 | */
53 | public static RestaurantProfileFragment newInstance() {
54 | RestaurantProfileFragment fragment = new RestaurantProfileFragment();
55 | Bundle args = new Bundle();
56 | fragment.setArguments(args);
57 | return fragment;
58 | }
59 |
60 | @Override
61 | public void onCreate(Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 | }
64 |
65 | @Override
66 | public void onActivityCreated(Bundle savedInstanceState) {
67 | super.onActivityCreated(savedInstanceState);
68 | RestaurantActivity rActivity = (RestaurantActivity) getActivity();
69 | restaurant = rActivity.getRestaurant();
70 | }
71 |
72 | @Override
73 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
74 | Bundle savedInstanceState) {
75 | // Inflate the layout for this fragment
76 | View view = inflater.inflate(R.layout.restaurantui_fragment_profile, container, false);
77 |
78 | // Retrieve info
79 | RestaurantActivity rActivity = (RestaurantActivity) getActivity();
80 | restaurant = rActivity.getRestaurant();
81 |
82 | // Text View
83 | accountTextView = (TextView) view.findViewById(R.id.resId);
84 | nameTextView = (TextView) view.findViewById(R.id.resName);
85 | accountTextView.setText(restaurant.getEmail());
86 | nameTextView.setText(restaurant.getName());
87 | picture = (ImageView) view.findViewById(R.id.res_picture);
88 | picture.setImageBitmap(restaurant.getPicture());
89 |
90 | // Edit View
91 | passwordText = (EditText) view.findViewById(R.id.resPassword);
92 | categoryText = (EditText) view.findViewById(R.id.resCategory);
93 | phoneText = (EditText) view.findViewById(R.id.resPhone);
94 | cardText = (EditText) view.findViewById(R.id.resCard);
95 | addressText = (EditText) view.findViewById(R.id.resAddress);
96 | locationText = (EditText) view.findViewById(R.id.resLocation);
97 | pictureURLText = (EditText) view.findViewById(R.id.pic_url);
98 |
99 | // Set Edit View
100 | passwordText.setText(restaurant.getPassword());
101 | categoryText.setText(restaurant.getCategory());
102 | phoneText.setText(restaurant.getPhone());
103 | cardText.setText(restaurant.getCard());
104 | addressText.setText(restaurant.getAddress());
105 | locationText.setText(restaurant.getLocation());
106 | pictureURLText.setText(restaurant.getPictureURL());
107 |
108 | // Set Edit View Enable
109 | passwordText.setEnabled(false);
110 | categoryText.setEnabled(false);
111 | phoneText.setEnabled(false);
112 | cardText.setEnabled(false);
113 | addressText.setEnabled(false);
114 | locationText.setEnabled(false);
115 | pictureURLText.setEnabled(false);
116 |
117 | // Edit Button
118 | Button editRestaurant = (Button) view.findViewById(R.id.editButton);
119 | editRestaurant.setOnClickListener(new View.OnClickListener() {
120 | @Override
121 | public void onClick(View view) {
122 | // edit restaurant
123 | passwordText.setEnabled(true);
124 | categoryText.setEnabled(true);
125 | phoneText.setEnabled(true);
126 | cardText.setEnabled(true);
127 | addressText.setEnabled(true);
128 | locationText.setEnabled(true);
129 | pictureURLText.setEnabled(true);
130 | }
131 | });
132 |
133 | // Save Button
134 | Button saveRestaurant = (Button) view.findViewById(R.id.saveButton);
135 | saveRestaurant.setOnClickListener(new View.OnClickListener() {
136 | @Override
137 | public void onClick(View view) {
138 | // params: Email, Name, Phone, Password, CardNumber, Address, Category, Location, Picture
139 | String[] params = new String[9];
140 | params[0] = restaurant.getEmail();
141 | params[1] = restaurant.getName();
142 | params[2] = phoneText.getText().toString().trim();
143 | params[3] = passwordText.getText().toString().trim();
144 | params[4] = cardText.getText().toString().trim();
145 | params[5] = addressText.getText().toString().trim();
146 | params[6] = categoryText.getText().toString().trim();
147 | params[7] = locationText.getText().toString().trim();
148 | params[8] = pictureURLText.getText().toString().trim();
149 |
150 | restaurant.updateProfile(params);
151 | restaurant.setShowToast(RestaurantProfileFragment.this);
152 |
153 | // Set Edit View Enable
154 | passwordText.setEnabled(false);
155 | categoryText.setEnabled(false);
156 | phoneText.setEnabled(false);
157 | cardText.setEnabled(false);
158 | addressText.setEnabled(false);
159 | locationText.setEnabled(false);
160 | pictureURLText.setEnabled(false);
161 | }
162 | });
163 | return view;
164 | }
165 |
166 | @Override
167 | public void setToast(String str) {
168 | Toast.makeText(getActivity(),
169 | str, Toast.LENGTH_LONG).show();
170 | }
171 |
172 | private class UpdateRestaurant extends AsyncTask {
173 | protected String doInBackground(String... sql) {
174 | return create(sql[0]);
175 | }
176 | protected void onPostExecute(String results) {
177 | if (results.equals("true")) {
178 | Toast.makeText(getActivity(),
179 | "New profile saved successfully.", Toast.LENGTH_LONG).show();
180 | } else {
181 | Toast.makeText(getActivity(),
182 | "Sorry, save failed.", Toast.LENGTH_LONG).show();
183 | }
184 | }
185 | private String create(String sql) {
186 | String results = "";
187 | try {
188 | results = Client.createData(sql);
189 | } catch (ConnectionException e) {
190 | e.printStackTrace();
191 | }
192 | return results;
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/customerui/PlaceOrderActivity.java:
--------------------------------------------------------------------------------
1 | package foodeliver.customerui;
2 |
3 | import android.app.ListActivity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.AsyncTask;
7 | import android.os.Bundle;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.AdapterView;
12 | import android.widget.AdapterView.OnItemSelectedListener;
13 | import android.widget.ArrayAdapter;
14 | import android.widget.Button;
15 | import android.widget.EditText;
16 | import android.widget.ImageView;
17 | import android.widget.Spinner;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import java.text.SimpleDateFormat;
22 | import java.util.Date;
23 | import java.util.List;
24 |
25 | import foodeliver.R;
26 | import foodeliver.entities.Food;
27 | import foodeliver.entities.FoodMenu;
28 | import foodeliver.entities.FoodOrder;
29 | import foodeliver.entities.Restaurant;
30 | import foodeliver.exception.ConnectionException;
31 | import foodeliver.remote.Client;
32 | import foodeliver.utility.Transition;
33 |
34 | public class PlaceOrderActivity extends ListActivity implements Transition {
35 |
36 | private FoodMenu foodMenu;
37 |
38 | private String customerEmail = "";
39 |
40 | private String customerPhone = "";
41 |
42 | private String customerAddr = "";
43 |
44 | private Restaurant restaurant;
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.customerui_activity_place_order);
50 | Bundle extras = getIntent().getExtras();
51 | if (extras != null) {
52 | customerEmail = extras.getString("customer_email");
53 | restaurant = new Restaurant();
54 | restaurant.readProfile(extras.getString("restaurant_email"));
55 | new GetInfoTask().execute("SELECT Name, Address, Phone" +
56 | " FROM RESTAURANT WHERE Email='" + extras.getString("restaurant_email") + "';");
57 | customerPhone = extras.getString("customer_phone");
58 | customerAddr = extras.getString("customer_addr");
59 | EditText addrText = (EditText) findViewById(R.id.editTextAddr);
60 | addrText.setText(customerAddr);
61 | EditText phoneText = (EditText) findViewById(R.id.editTextPhone);
62 | phoneText.setText(customerPhone);
63 | foodMenu = new FoodMenu();
64 | foodMenu.readItem(restaurant.getEmail());
65 | setListAdapter(new ListViewAdapter(PlaceOrderActivity.this, foodMenu.getItems()));
66 | }
67 | Button placeOrder = (Button) findViewById(R.id.place_order);
68 | placeOrder.setOnClickListener(new View.OnClickListener() {
69 | @Override
70 | public void onClick(View view) {
71 | // place order operations
72 | boolean validOrder = false;
73 | double totalPrice = 0;
74 | EditText addrText = (EditText) findViewById(R.id.editTextAddr);
75 | String addr = addrText.getText().toString();
76 | EditText phoneText = (EditText) findViewById(R.id.editTextPhone);
77 | String phone = phoneText.getText().toString();
78 | Spinner spinnerOnOff = (Spinner) findViewById(R.id.spinnerOnOff);
79 | for (Food item : foodMenu.getItems()) {
80 | if (item.getQuantity() > 0) {
81 | validOrder = true;
82 | totalPrice = item.getQuantity() * Double.parseDouble(item.getPrice());
83 | }
84 | }
85 | if (addr == null || addr.length() == 0 || phone == null || phone.length() == 0) {
86 | validOrder = false;
87 | }
88 | if (!validOrder) {
89 | Toast.makeText(PlaceOrderActivity.this, "Invalid order information.", Toast.LENGTH_SHORT).show();
90 | } else {
91 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
92 | Date date = new Date();
93 | String orderTime = dateFormat.format(date);
94 | String payment = spinnerOnOff.getSelectedItem().toString();
95 | System.out.println("Order Time: " + orderTime);
96 | FoodOrder foodOrder = new FoodOrder();
97 | foodOrder.setTransition(PlaceOrderActivity.this);
98 | foodOrder.createOrder(customerEmail, restaurant.getEmail(), orderTime,
99 | phone, addr, payment, totalPrice, foodMenu.getItems());
100 | }
101 | }
102 | });
103 | }
104 |
105 | @Override
106 | public void transit() {
107 | Intent intent = new Intent(getApplicationContext(), CustomerActivity.class);
108 | intent.putExtra("customer_email", customerEmail);
109 | startActivity(intent);
110 | }
111 |
112 | @Override
113 | public void setToast(String str) {
114 | Toast.makeText(this, str, Toast.LENGTH_LONG).show();
115 | }
116 |
117 | private class ListViewAdapter extends ArrayAdapter {
118 |
119 | public ListViewAdapter(Context context, List items) {
120 | super(context, R.layout.customerui_placeorderitem, items);
121 | }
122 |
123 | @Override
124 | public View getView(int position, View view, ViewGroup parent) {
125 | LayoutInflater inflater = LayoutInflater.from(getContext());
126 | final Food item = getItem(position);
127 | view = inflater.inflate(R.layout.customerui_placeorderitem, parent, false);
128 | TextView idView = (TextView) view.findViewById(R.id.menuidTextView);
129 | TextView nameView = (TextView) view.findViewById(R.id.menuNameTextView);
130 | ImageView picView = (ImageView) view.findViewById(R.id.menuPicView);
131 | TextView priceView = (TextView) view.findViewById(R.id.priceTextView);
132 | Spinner spinner = (Spinner) view.findViewById(R.id.quantityEdit);
133 |
134 | idView.setText(String.valueOf(position + 1));
135 | nameView.setText(item.getName());
136 | picView.setImageBitmap(item.getPicture());
137 | priceView.setText(String.valueOf(item.getPrice()));
138 | spinner.setSelection(item.getQuantity());
139 |
140 | spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
141 | @Override
142 | public void onItemSelected(AdapterView> parentView, View selectedItemView, int position, long id) {
143 | item.setQuantity(position);
144 | }
145 |
146 | @Override
147 | public void onNothingSelected(AdapterView> parentView) {
148 | setSelection(0);
149 | }
150 |
151 | });
152 |
153 | return view;
154 | }
155 | }
156 |
157 | private class GetInfoTask extends AsyncTask {
158 | protected String doInBackground(String... sql) {
159 | return search(sql[0]);
160 | }
161 | protected void onPostExecute(String sqlResult) {
162 | String[] results = sqlResult.split("\n");
163 | for (String result : results) {
164 | String[] elements = result.split("\t");
165 | if (elements.length > 2) {
166 | TextView resName = (TextView) findViewById(R.id.resNameTextView);
167 | TextView resAddr = (TextView) findViewById(R.id.resAddrTextView);
168 | TextView resPhone = (TextView) findViewById(R.id.resPhoneTextView);
169 | resName.setText(elements[0]);
170 | resAddr.setText(elements[1]);
171 | resPhone.setText(elements[2]);
172 | }
173 | }
174 | }
175 | private String search(String sql) {
176 | String results = "";
177 | try {
178 | results = Client.readData(sql);
179 | } catch (ConnectionException e) {
180 | e.printStackTrace();
181 | }
182 | return results;
183 | }
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/FooDelivery_client/app/src/main/java/foodeliver/customerui/SearchFragment.java:
--------------------------------------------------------------------------------
1 | package foodeliver.customerui;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.os.Bundle;
7 | import android.support.v4.app.ListFragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.AdapterView;
12 | import android.widget.AdapterView.OnItemClickListener;
13 | import android.widget.ArrayAdapter;
14 | import android.widget.Button;
15 | import android.widget.EditText;
16 | import android.widget.ImageView;
17 | import android.widget.ListView;
18 | import android.widget.Spinner;
19 | import android.widget.TextView;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import foodeliver.R;
25 | import foodeliver.entities.Restaurant;
26 | import foodeliver.remote.DBTask;
27 | import foodeliver.remote.GetPicture;
28 | import foodeliver.utility.DataSearch;
29 | import foodeliver.utility.PictureSearch;
30 |
31 | /**
32 | * Search restaurant fragment.
33 | * @author Jiaqi Zhang
34 | */
35 | public class SearchFragment extends ListFragment implements OnItemClickListener, PictureSearch, DataSearch {
36 |
37 | /**
38 | * List view.
39 | */
40 | private ListView searchListView;
41 |
42 | /**
43 | * Items in the list view.
44 | */
45 | private List items;
46 |
47 | private String customerEmail = "";
48 |
49 | private String initialLoc = "";
50 |
51 | private EditText searchTerm;
52 | private Spinner spinnerCategory;
53 | private Spinner spinnerLocation;
54 |
55 | private static final String[] LOCATIONS = new String[]{"All", "ShadySide",
56 | "Squirrel Hill", "North Oakland", "South Oakland"};
57 |
58 | @Override
59 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
60 | View view = inflater.inflate(R.layout.customerui_fragment_search, container, false);
61 | Button search = (Button) view.findViewById(R.id.search_submit);
62 | searchTerm = (EditText) view.findViewById(R.id.editTextSearch);
63 | spinnerCategory = (Spinner) view.findViewById(R.id.spinnerCategory);
64 | spinnerLocation = (Spinner) view.findViewById(R.id.spinnerLocation);
65 | search.setOnClickListener(new View.OnClickListener() {
66 | @Override
67 | public void onClick(View view) {
68 | // search restaurants
69 | String nameSearch = searchTerm.getText().toString().trim();
70 | String category = (String) spinnerCategory.getSelectedItem();
71 | String location = (String) spinnerLocation.getSelectedItem();
72 | StringBuilder sql = new StringBuilder("SELECT Email, Name, Category, Location, Picture FROM RESTAURANT");
73 | int count = 0;
74 | if (nameSearch.length() != 0 || !category.equals("All") || !location.equals("All")) {
75 | sql.append(" WHERE");
76 | if (nameSearch.length() != 0) {
77 | sql.append(" Name='").append(nameSearch).append("'");
78 | count++;
79 | }
80 | if (!category.equals("All")) {
81 | if (count > 0) {
82 | sql.append(" AND");
83 | }
84 | sql.append(" Category='").append(category).append("'");
85 | count++;
86 | }
87 | if (!location.equals("All")) {
88 | if (count > 0) {
89 | sql.append(" AND");
90 | }
91 | sql.append(" Location='").append(location).append("'");
92 | count++;
93 | }
94 | }
95 | sql.append(";");
96 | DBTask dbT = new DBTask();
97 | ArrayList list = new ArrayList();
98 | list.add(sql.toString());
99 | dbT.getResult(list, SearchFragment.this, "result");
100 | }
101 | });
102 | return view;
103 | }
104 |
105 | @Override
106 | public void onActivityCreated(Bundle savedInstanceState) {
107 | super.onActivityCreated(savedInstanceState);
108 | searchListView = getListView();
109 | CustomerActivity cActivity = (CustomerActivity) getActivity();
110 | customerEmail = cActivity.getCustomerEmail();
111 | initialLoc = cActivity.getInitialLoc();
112 | items = new ArrayList();
113 |
114 | int index = -1;
115 | for (int i = 0; initialLoc != null && i < LOCATIONS.length; i++) {
116 | if(initialLoc.equals(LOCATIONS[i])) {
117 | index = i;
118 | }
119 | }
120 | DBTask dbT = new DBTask();
121 | if (index <= 0) {
122 | ArrayList list = new ArrayList();
123 | list.add("SELECT Email, Name, Category, Location, Picture FROM RESTAURANT;");
124 | dbT.getResult(list, SearchFragment.this, "result");
125 | } else {
126 | spinnerLocation.setSelection(index);
127 | ArrayList list = new ArrayList();
128 | list.add("SELECT Email, Name, Category, Location, Picture" +
129 | " FROM RESTAURANT WHERE Location='" + initialLoc + "';");
130 | dbT.getResult(list, SearchFragment.this, "result");
131 | }
132 | }
133 |
134 | @Override
135 | public void onViewCreated(View view, Bundle savedInstanceState) {
136 | super.onViewCreated(view, savedInstanceState);
137 | getListView().setDivider(null);
138 | }
139 |
140 | public void pictureReady(ArrayList pictures) {
141 | for (int i = 0; i < pictures.size() && i < items.size(); i++) {
142 | items.get(i).setPicture(pictures.get(i));
143 | }
144 | setListAdapter(new ListViewAdapter(getActivity(), items));
145 |
146 | searchListView.setOnItemClickListener(SearchFragment.this);
147 | }
148 |
149 | public void dbResultReady(String result) {
150 | items.clear();
151 | ArrayList searchPics = new ArrayList();
152 | String[] results = result.split("\n");
153 | for (String r : results) {
154 | String[] elements = r.split("\t");
155 | if (elements.length > 4) {
156 | items.add(new Restaurant(elements[0], elements[1], elements[2], elements[3], elements[4]));
157 | searchPics.add(elements[4]);
158 | }
159 | }
160 |
161 | GetPicture gp = new GetPicture();
162 | gp.search(searchPics, SearchFragment.this);
163 | }
164 |
165 | public void updateReady(String result) {}
166 | public void dbDetailReady(String result) {}
167 |
168 | @Override
169 | public void deleteReady(String result) {
170 |
171 | }
172 |
173 | @Override
174 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
175 | Intent intent = new Intent(getActivity().getApplicationContext(), PlaceOrderActivity.class);
176 | CustomerActivity cActivity = (CustomerActivity) getActivity();
177 | intent.putExtra("customer_email", customerEmail);
178 | intent.putExtra("restaurant_email", items.get(position).getEmail());
179 | intent.putExtra("customer_phone", cActivity.getCustomerPhone());
180 | intent.putExtra("customer_addr", cActivity.getCustomerAddr());
181 | startActivity(intent);
182 | }
183 |
184 | private class ListViewAdapter extends ArrayAdapter {
185 |
186 | public ListViewAdapter(Context context, List items) {
187 | super(context, R.layout.customerui_fragment_searchitem, items);
188 | }
189 |
190 | @Override
191 | public View getView(int position, View view, ViewGroup parent) {
192 | LayoutInflater inflater = LayoutInflater.from(getContext());
193 | view = inflater.inflate(R.layout.customerui_fragment_searchitem, parent, false);
194 | TextView name = (TextView) view.findViewById(R.id.resNameTextView);
195 | ImageView pic = (ImageView) view.findViewById(R.id.resPicView);
196 | TextView category = (TextView) view.findViewById(R.id.categoryTextView);
197 | TextView location = (TextView) view.findViewById(R.id.locTextView);
198 |
199 | Restaurant item = getItem(position);
200 | name.setText(item.getName());
201 | pic.setImageBitmap(item.getPicture());
202 | category.setText(item.getCategory());
203 | location.setText(item.getLocation());
204 |
205 | return view;
206 | }
207 | }
208 | }
209 |
--------------------------------------------------------------------------------