Online Food Order App Android Studio

Online Food Order App Android Studio – In this article I will explain how to create online food ordering android application on Android Studio platform. Which is not only food you can also add more services like groceries, electronic gadgets and more things. So its perfect for online grocery order delivery android app and food order delivery in Android Studio IDE. In the market Swiggy, Zomato Uber and more popular food ordering company provide good services for all customers who living in cities.

WordPress simplify our work to do greatest work like E-Commerce app development. Before coming WordPress, most of developers struggle to create and develop ecommerce application like Flipkart, amazon, swiggy, grofers and popular ecommerce websites. WordPress provide plugins features so we can download and install woocommerce plugin for develop the ecart application.

Create E-Commerce App

Before starting this project, you have to basic knowledge in WordPress and such plugin for how to handle and customize the theme as our wish. Once you lean WordPress and woocommerce then you can easily develop ecommerce application like swiggy,flipkart. Beginning is always hardest so try to learn deeply after that you got idea for programming side.

Here we have to develop native android application using java in Android Studio IDE. In the market there are more free theme templates are available to make a perfect ecommerce application like food grocery delivery applications. Just know basic things of WordPress and woocommerce if you want to use free template themes.

Android Food Ordering App Features

There are features available in this food ordering app, here I will list advantages of food ordering app.

General functions:

  • User registration.
  • Viewing food menu.
  • Filtering food menu by price.
  • Viewing product details.

Member functions:

  • Login as a member.
  • View food menu and product information.
  • Filtering food menu by price.
  • Place food orders.

Admin functions:

  • Add new products to the menu.
  • Delete products from the menu.
  • Modify product information.
  • Confirm orders placed by users.

Create New Project

Okay lets start, create new project and choose empty template for make new own design. After creating the project first we have to create login registration form for fill the details through the users. So first create one activity for Login page, open LoginActivity.java file and add following below code,

package com.cmbpizza.razor.colombopizza;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.Patterns;
import android.view.Display;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class LoginScreen extends Activity implements View.OnClickListener, GestureDetector.OnGestureListener{

    Button LoginAccessButton, MainLoginButton, RegisterButton;
    AutoCompleteTextView LoginEmail;
    EditText FirstName, LastName, Mobile, Email, Password, ConfirmPassword, LoginPassword;
    CheckBox CheckTnC;
    ImageView LoginBackgroundImage, LoginBottomImage;
    GestureDetector gestureDetector;
    private static SQLLiteHelperProducts sqLiteHelper;
    public Dialog loginDialog; //creating a new instance of the Dialog class object, and specifying its context as the current class

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_screen);
        //this is to prevent the keyboard from showing when the app starts
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        initializeComponents();
        initializeListeners();
        initializeAnimators();
        initializeGestures();
        sqlLiteDB();
        setBackgroundImage();
    }

    //initializing the buttons and views that is being used in this class
    private void initializeComponents(){
        //initializing and declaring button to this java class by referring to the button ID specified in the XML
        LoginAccessButton = findViewById(R.id.btnLogin);
        RegisterButton = findViewById(R.id.btnRegister);
        LoginBottomImage = findViewById(R.id.login_bottom_image);
        LoginBackgroundImage = findViewById(R.id.loginBackgroundImage);

    //used to initialize the animations that is used in this activity
    private void initializeAnimators(){
        Drawable drawable =  LoginBottomImage.getDrawable();
        if(drawable instanceof Animatable){
            ((Animatable)drawable).start();
        }
    }

    //setting a click event listener to these buttons
    private void initializeListeners(){
        LoginAccessButton.setOnClickListener(this);
        RegisterButton.setOnClickListener(this);
        MainLoginButton.setOnClickListener(this);
    }

    //used to initialize the gestures used in this activity
    private void initializeGestures(){
        //this gesture detector will monitor for any gestures performed in this activity
        //the on touch listener is used to restrain the gesture monitoring activity to
        //be constrained to a particular view in this case the bottom of the screen layout)
        gestureDetector = new GestureDetector(LoginScreen.this ,this);
        findViewById(R.id.login_bottom_image).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return gestureDetector.onTouchEvent(motionEvent);
            }
        });
    }

    @Override
    public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent motionEvent) {

    }

    //this event will fire when the user does the fling motion on the screen
    //when a user drags and lifts their finger quickly
    @Override
    public boolean onFling(MotionEvent start, MotionEvent end, float v, float v1) {
        if(start.getY() > end.getY()){
            //if the user flings from bottom to top (slide up)
            Intent newIntent = new Intent(LoginScreen.this, UserMenu.class);
            startActivity(newIntent);
            overridePendingTransition(R.anim.layout_slide_up, R.anim.back_layout_slide_up);
            return true;
        } else if(start.getX() > end.getX() || start.getY() < end.getY() || start.getX() < end.getX()){
            //ignore other fling motions in other directions
            return false;
        } else{
            return false;
        }
    }

    //this method is used to create a database
    private void sqlLiteDB() {
        sqLiteHelper = new SQLLiteHelperProducts(LoginScreen.this, "ProductDB", null, 1);
        sqLiteHelper.dataQuery("CREATE TABLE IF NOT EXISTS userTable (userId INTEGER PRIMARY KEY AUTOINCREMENT, userFirstName VARCHAR, userLastName VARCHAR, userMobile VARCHAR, userEmail VARCHAR, userPassword VARCHAR)");

    }

    private void checkUser(){
        String AdminEmail = "admin";
        String AdminPass = "pass";
        if(inputLoginValidation()){
            String Email = LoginEmail.getText().toString();
            String Password = LoginPassword.getText().toString();
            if(Email.equals(AdminEmail) && Password.equals(AdminPass)){
                Intent newIntent = new Intent(LoginScreen.this, AdminMenu.class);
                startActivity(newIntent);
                clearEditTextValues();
                loginDialog.cancel();
            } else {
                if(sqLiteHelper.checkEmail(Email)){
                    if(sqLiteHelper.checkPassword(Email, Password)){
                        int UserId = sqLiteHelper.getUserId(Email);
                        Intent newIntent = new Intent(LoginScreen.this, UserMenu.class);
                        newIntent.putExtra("userId", UserId);
                        startActivity(newIntent);
                        clearEditTextValues();
                        loginDialog.cancel();
                    } else {
                        Toast.makeText(LoginScreen.this, "Your password is incorrect, please try again", Toast.LENGTH_SHORT).show();
                        LoginPassword.requestFocus();
                    }
                } else {
                    Toast.makeText(LoginScreen.this, "Your email does not exist", Toast.LENGTH_SHORT).show();
                    LoginEmail.requestFocus();
                }
            }
        }
    }

    private void clearEditTextValues(){
        LoginEmail.getText().clear();
        LoginPassword.getText().clear();
    }

    private void registerUser(){
        if(inputValidation()){
            String UserFirstName = FirstName.getText().toString();
            String UserLastName = LastName.getText().toString();
            String UserMobile = Mobile.getText().toString();
            String UserEmail = Email.getText().toString();
            String UserPassword = Password.getText().toString();
            sqLiteHelper.registerUser(UserFirstName, UserLastName, UserMobile, UserEmail, UserPassword);
            Toast.makeText(this, "Registration Successful", Toast.LENGTH_SHORT).show();
            clearRegistrationForm();
            int UserId = sqLiteHelper.getUserId(UserEmail);
            Intent newIntent = new Intent(LoginScreen.this, UserMenu.class);
            newIntent.putExtra("userId", UserId);
            startActivity(newIntent);
            overridePendingTransition(R.anim.layout_slide_up, R.anim.back_layout_slide_up);
        }
    }

    private void clearRegistrationForm() {
        FirstName.getText().clear();
        LastName.getText().clear();
        Mobile.getText().clear();
        Email.getText().clear();
        Password.getText().clear();
        ConfirmPassword.getText().clear();
        CheckTnC.setSelected(false);
    }

    //this method will check the input fields and validate them before submitting them
    private boolean inputValidation() {
        boolean valid;
        String UserFirstName = FirstName.getText().toString();
        String UserLastName = LastName.getText().toString();
        String UserMobile = Mobile.getText().toString();
        String UserEmail = Email.getText().toString();
        String UserPassword = Password.getText().toString();
        String UserConfirmPassword = ConfirmPassword.getText().toString();
        Boolean TnCConfirmed = CheckTnC.isChecked();
        if (UserFirstName.isEmpty()) {
            valid = false;
            FirstName.requestFocus();
            Toast.makeText(this, "Please enter your First Name", Toast.LENGTH_SHORT).show();
        } else if (UserLastName.isEmpty()) {
            valid = false;
            LastName.requestFocus();
            Toast.makeText(this, "Please enter your Last Name", Toast.LENGTH_SHORT).show();
        } else if (UserMobile.isEmpty()) {
            valid = false;
            Mobile.requestFocus();
            Toast.makeText(this, "Please enter Mobile Number", Toast.LENGTH_SHORT).show();
        } else if (UserEmail.isEmpty()) {
            valid = false;
            Email.requestFocus();
            Toast.makeText(this, "Please enter your Email Address", Toast.LENGTH_SHORT).show();
        } else if (!Patterns.EMAIL_ADDRESS.matcher(UserEmail).matches()) {
            valid = false;
            LoginEmail.requestFocus();
        return valid;
    }
}

After that we have to create Admin activity for add and remove products through login form for admin only. The code’s are long so in below i have to include source code of Android Food Ordering App in Android Studio.

Run Projects – Online Food Order App

Once the application loads fully, do the following steps to execute. Open Device File Explorer. Go to data/data/[src location]/databases. Upload the database of ‘ProductDB‘ file to this folder. Restart the app, to initialize the Database.

Leave a Reply