Roger IMP Assignment1GoNut

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

Manifest

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.GoNutsApp"
tools:targetApi="31">
<activity
android:name=".generateTicket"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".completeBookingPage"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".ViewHistoryPage"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".OnlineBookingPage"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".UserRegister"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".LoginSucceed"
android:exported="false"
android:label="Logout"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>

</manifest>

Java : DbAdapter
//DBAHelper
package com.example.gonutsapp;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBAdapter {


//tblOrder
static final String KEY_ticketId = "ticketID";
static final String KEY_userPhone = "userPhone";
static final String KEY_orderId = "orderId";
static final String KEY_orderDate = "orderDate";
static final String KEY_pickUpDate = "pickUpDate";
static final String KEY_pickupTime = "pickupTime";
static final String KEY_totalAmt = "totalAmt";

//tblOrderItem
static final String KEY_itemId = "itemId";
static final String KEY_qtyOrdered = "qtyOrdered";

//tblAccount
static final String KEY_phoneNum = "phoneNum";
static final String KEY_password = "password";

static final String TAG = "DBAdapter";


static final String DATABASE_NAME = "dbGoNut";
static final String DATABASE_TABLE_tblOrder = "tblOrder";
static final String DATABASE_TABLE_tblOderItem = "tblOrderItem";
static final String DATABASE_TABLE_tblAccount = "tblAccount";
static final int DATABASE_VERSION = 2;

static final String DATABASE_CREATE_tblOrder =


"create table tblOrder (ticketID integer primary key autoincrement,
userPhone text not null, orderId integer not null, "
+ "orderDate text not null, pickUpDate text not null, pickupTime
text not null, totalAmt text not null);";

static final String DATABASE_CREATE_tblOrder_Item =


"create table tblOrderItem (orderId integer primary key
autoincrement, itemId text not null, qtyOrdered text not null);";

static final String DATABASE_CREATE_tblAccount =


"create table tblAccount (phoneNum text primary key, password
text not null);";

final Context context;

DatabaseHelper DBHelper;
SQLiteDatabase db;

public DBAdapter(Context ctx)


{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper


{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db)
{
try {
db.execSQL(DATABASE_CREATE_tblOrder);
db.execSQL(DATABASE_CREATE_tblOrder_Item);
db.execSQL(DATABASE_CREATE_tblAccount);
} catch (SQLException e) {
e.printStackTrace();
}
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion + "
to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
}

//---opens the database---


public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}

//---insert a contact into the tblAccount in database---


public long insertContactIntotblAccount(String phoneNum, String
password)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_phoneNum, phoneNum);
initialValues.put(KEY_password, password);
return db.insert(DATABASE_TABLE_tblAccount, null, initialValues);
}

//---insert a contact into the tblOderItem in database---


public long insertContactIntotblOrderItem(String itemId, String
qtyOrdered)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_itemId, itemId);
initialValues.put(KEY_qtyOrdered, qtyOrdered);
return db.insert(DATABASE_TABLE_tblOderItem, null, initialValues);
}

//---insert a contact into the tblOrder in database---


public long insertContactIntotblOrder(String userPhone, Integer
orderId, String orderDate, String pickupDate, String pickupTime, String
totalAmt)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_userPhone, userPhone);
initialValues.put(KEY_orderId, orderId);
initialValues.put(KEY_orderDate, orderDate);
initialValues.put(KEY_pickUpDate, pickupDate);
initialValues.put(KEY_pickupTime, pickupTime);
initialValues.put(KEY_totalAmt, totalAmt);
return db.insert(DATABASE_TABLE_tblOrder, null, initialValues);
}

//---retrieves the userAcc contacts


public Cursor getAllContacts()
{
return db.query(DATABASE_TABLE_tblAccount, new String[]
{KEY_phoneNum, KEY_password}
, null, null, null, null, null);
}

//---retrieves the orderItem contacts


public Cursor getAllOrderItemContacts(){
return db.query(DATABASE_TABLE_tblOderItem, new String[]
{KEY_orderId, KEY_itemId, KEY_qtyOrdered}
, null,null,null,null,null);
}

//---retrieves the order contacts


public Cursor getAllOrderContacts(){
return db.query(DATABASE_TABLE_tblOrder, new String[]{KEY_ticketId,
KEY_userPhone, KEY_orderId, KEY_orderDate, KEY_pickUpDate, KEY_pickupTime,
KEY_totalAmt}
, null,null,null,null,null);
}

//---retrieves a particular contact---


public Cursor getContact(String phoneNum) throws SQLException
{
Cursor mCursor =
db.query(true, DATABASE_TABLE_tblAccount, new String[]
{KEY_phoneNum,
KEY_password}, KEY_phoneNum + "=" + phoneNum, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}

//---updates a contact---
/*public boolean updateContact(long rowId, String name, String email)
{
ContentValues args = new ContentValues();
args.put(KEY_NAME, name);
args.put(KEY_EMAIL, email);
return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId,
null) > 0;
}*/

Java : Main Activity


package com.example.gonutsapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText userPhone, userPassword;


Button btnLogin;
Intent i;
DBAdapter db;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

db = new DBAdapter(this);
userPhone = findViewById(R.id.editTxtPhoneNum);
userPassword = findViewById(R.id.editTxtPassword);
btnLogin = findViewById(R.id.btnLogin);

public void Login(View view){


db.open();
String getUserPhone = userPhone.getText().toString().trim();
String getUserPassword = userPassword.getText().toString().trim();
Integer found = 0;
Cursor c = db.getAllContacts();
if (c.moveToFirst())
{
do {
if(getUserPhone.equals(c.getString(0)) &&
getUserPassword.equals(c.getString(1)))
{
found = 1;
break;
}
} while (c.moveToNext());
}

if(found == 1)
{
i = new Intent(MainActivity.this, LoginSucceed.class);
i.putExtra("userPhone", getUserPhone);
startActivity(i);
db.close();
}
else if(getUserPhone.isEmpty() || getUserPassword.isEmpty())
{
Toast.makeText(this, "Please fill in user phone or password !",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "User phone or password incorrect !",
Toast.LENGTH_SHORT).show();
}

public void Register(View view){


i = new Intent(MainActivity.this, UserRegister.class);
startActivity(i);
}

public void Reset(View view){


userPhone.setText("");
userPassword.setText("");
}
}

XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="188dp"
android:text="Login Page"
android:textSize="150px"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/editTxtPhoneNum"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="284dp"
android:hint="Phone Number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/editTxtPassword"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="332dp"
android:inputType="textPassword"
android:hint="Password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/registerTextClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="412dp"
android:onClick="Register"
android:text="Register here"
android:textColor="@color/purple_700"
android:textSize="50px"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.739"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="412dp"
android:text="Not a user yet ?"
android:textColor="@color/material_dynamic_tertiary50"
android:textSize="50px"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.289"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginTop="504dp"
android:onClick="Reset"
android:text="RESET"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.765"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="52dp"
android:layout_marginTop="504dp"
android:onClick="Login"
android:text="LOGIN"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.013"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

JAVA : Login Succed


package com.example.gonutsapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class LoginSucceed extends AppCompatActivity {


Intent i;
String userPhone;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_succeed);
Intent intent = getIntent();
userPhone = intent.getStringExtra("userPhone");
}

public void BookingPage(View view){

i = new Intent(LoginSucceed.this, OnlineBookingPage.class);


i.putExtra("userPhone", userPhone);
startActivity(i);
}

public void ViewHistoryPage(View view){


i = new Intent(LoginSucceed.this, ViewHistoryPage.class);
i.putExtra("userPhone", userPhone);
startActivity(i);
}
}

XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginSucceed">

<TextView
android:id="@+id/LoginSucceedTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="72dp"
android:text="DONUT HERE !"
android:textSize="50dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.493"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnBooking"
android:layout_width="500dp"
android:layout_height="100dp"
android:layout_marginTop="216dp"
android:text="Online Booking"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:onClick="BookingPage"
/>

<Button
android:id="@+id/btnViewHistory"
android:layout_width="500dp"
android:layout_height="100dp"
android:layout_marginTop="356dp"
android:text="View History"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.494"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:onClick="ViewHistoryPage"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Java : Online Booking Page


package com.example.gonutsapp;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;

public class OnlineBookingPage extends AppCompatActivity implements


AdapterView.OnItemSelectedListener{

EditText donutFlavour, coffeeType, pickUpDate, pickUpTime, donutNumber,


coffeeNumber;
Button completeOrder;
Spinner donutFlavourSpinner, donutNumberSpinner, coffeeTypeSpinner;
int mYear, mMonth, mDay, mHour, mMinute;
String userPhone;
Intent i;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_online_booking_page);

Intent intent = getIntent();


userPhone = intent.getStringExtra("userPhone");

donutFlavour = (EditText) findViewById(R.id.txtFlavour);


donutFlavourSpinner = (Spinner)
findViewById(R.id.donutsFlavourSpinner);
donutFlavourSpinner.setOnItemSelectedListener(this);
donutNumber = (EditText) findViewById(R.id.txtNumberDonut);
donutNumberSpinner = (Spinner)
findViewById(R.id.totalNumberofDonutsSpinner);
donutNumberSpinner.setOnItemSelectedListener(this);

coffeeType = (EditText) findViewById(R.id.txtCoffee);


coffeeTypeSpinner = (Spinner) findViewById(R.id.coffeeTypeSpinner);
coffeeTypeSpinner.setOnItemSelectedListener(this);
coffeeNumber = (EditText) findViewById(R.id.txtNumberCoffeeOrder);

pickUpDate = (EditText) findViewById(R.id.txtPickUpDate);


pickUpTime = (EditText) findViewById(R.id.txtPickUpTime);

completeOrder = (Button) findViewById(R.id.completeButton);

String[] flavour = {"Flavour", "Banana", "Chocolate", "Almond",


"Grape", "Cheese",
"strawberry", "cola", "milk", "mint"};
String[] donutNum = {"6", "12", "24"};
String[] coffee = {"Coffee type","Black", "Cream", "Sweetener"};

ArrayAdapter<String> adapter = new

ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, flavour);
ArrayAdapter<String> adapter1 = new
ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, donutNum);
ArrayAdapter<String> adapter2 = new

ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, coffee);

donutFlavourSpinner.setAdapter(adapter);
donutNumberSpinner.setAdapter(adapter1);
coffeeTypeSpinner.setAdapter(adapter2);
}

public void onItemSelected(AdapterView<?> parent, View view, int


position, long id) {
// On selecting a spinner item
String donutItem =
donutFlavourSpinner.getSelectedItem().toString();
String donutItem2 =
donutNumberSpinner.getSelectedItem().toString();
String coffeeItem = coffeeTypeSpinner.getSelectedItem().toString();

donutFlavour.setText(donutItem);
coffeeType.setText(coffeeItem);
donutNumber.setText(donutItem2);
}

public void onNothingSelected(AdapterView<?> arg0) {


// TODO Auto-generated method stub
}

public void showDatePickerDialog(View view) {


// Get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(this, new
DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
pickUpDate.setText(dayOfMonth + "-" + (monthOfYear + 1) +
"-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}

public void showTimePickerDialog(View v)


{
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);

// Launch Time Picker Dialog


TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {

@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
pickUpTime.setText(hourOfDay + ":" + minute);
}
}, mHour, mMinute, false);
timePickerDialog.show();
}

public void completeOrder(View view){

String getDonutFlavour = donutFlavour.getText().toString().trim();


String getDonutNumber = donutNumber.getText().toString().trim();
String getCoffeeType = coffeeType.getText().toString().trim();
String getCoffeeCup = coffeeNumber.getText().toString().trim();
String getDate = pickUpDate.getText().toString().trim();
String getTime = pickUpTime.getText().toString().trim();

if(getDonutFlavour.equals("Flavour")){
Toast.makeText(this, "Please SELECT a donut flavour !",
Toast.LENGTH_SHORT).show();
}
else if(getCoffeeType.equals("Coffee type")){
Toast.makeText(this, "Please SELECT a coffee type !",
Toast.LENGTH_SHORT).show();
}
else if(getCoffeeCup.isEmpty()){
Toast.makeText(this, "Please DETERMINE how many cups of coffee
to order !", Toast.LENGTH_SHORT).show();
}
else if(getDate.isEmpty() || getTime.isEmpty()){
Toast.makeText(this, "Please SCHEDULE a date and time to pick
up the order !", Toast.LENGTH_SHORT).show();
}
else
{
i = new Intent(OnlineBookingPage.this ,
completeBookingPage.class);
i.putExtra("userPhone", userPhone);
i.putExtra("donutFlavour",getDonutFlavour);
i.putExtra("donutNumber",getDonutNumber);
i.putExtra("coffeeType",getCoffeeType);
i.putExtra("coffeeCup",getCoffeeCup);
i.putExtra("pickUpDate",getDate);
i.putExtra("pickUpTime",getTime);
startActivity(i);
}
}

public void BackToOnlineBookingPage(View view){


i = new Intent(OnlineBookingPage.this, LoginSucceed.class);
i.putExtra("userPhone", userPhone);
startActivity(i);
}

XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OnlineBookingPage">

<EditText
android:id="@+id/txtPickUpDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="356dp"
android:enabled="false"
android:hint="pick up date"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/completeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="476dp"
android:onClick="completeOrder"
android:text="Complete"
android:background="@drawable/custom_edit_text"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.28"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnBackToPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="476dp"
android:background="@drawable/custom_edit_text"
android:onClick="BackToOnlineBookingPage"
android:text="Back"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.715"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/txtPickUpTime"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="400dp"
android:enabled="false"
android:hint="pick up time"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Spinner
android:id="@+id/donutsFlavourSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="236dp"
android:spinnerMode="dropdown"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.545"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/txtNumberCoffeeOrder"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="288dp"
android:hint="cup"
android:inputType="number"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.87"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Spinner
android:id="@+id/coffeeTypeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="304dp"
android:spinnerMode="dropdown"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.545"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="228dp"
android:text="Donuts"

android:textSize="70px"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.11"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="296dp"
android:text="Coffee"

android:textSize="70px"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.126"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="360dp"

android:text="Schedule"
android:textSize="70px"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.039"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="356dp"
android:backgroundTint="@color/design_default_color_secondary"
android:onClick="showDatePickerDialog"
android:text="DATE"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.891"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Spinner
android:id="@+id/totalNumberofDonutsSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="236dp"
android:spinnerMode="dropdown"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.881"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="400dp"
android:backgroundTint="@color/design_default_color_secondary"
android:onClick="showTimePickerDialog"
android:text="TIME"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.891"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/txtNumberDonut"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="668dp"
android:visibility="invisible"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.984"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/txtFlavour"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="668dp"
android:visibility="invisible"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.061"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/txtCoffee"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="668dp"
android:visibility="invisible"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.674"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Java : View History
package com.example.gonutsapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class ViewHistoryPage extends AppCompatActivity{

XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewHistoryPage">

<Spinner
android:id="@+id/orderIDSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:spinnerMode="dropdown"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnShowContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:background="@drawable/custom_edit_text"
android:text="Show"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/orderId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50dp"
android:layout_marginTop="320dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.484"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java : complete Booking Page


package com.example.gonutsapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.text.DateFormat;
import java.util.Calendar;

public class completeBookingPage extends AppCompatActivity {


String donutFlavour, donutNumber, coffeeType, coffeeCup, pickUpDate,
pickUpTime, userPhone;
TextView txtUserPhone, txtDonutFlavour, txtDonutNumber, txtDonutPrice;
TextView txtCoffeeType, txtCoffeeCup, txtCoffeePrice;
TextView txtDate, txtTime, txtTotalAmt;
Button orderNow, backToPreviousPage;
double donutPrice, coffePrice, totalAmt;
double intDonutNumber, intCoffeeCup, donutTotal, coffeeTotal;
String donutItemId, coffeeItemId;
DBAdapter db;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complete_booking_page);

Intent intent = getIntent();


donutFlavour = intent.getStringExtra("donutFlavour");
donutNumber = intent.getStringExtra("donutNumber");
coffeeType = intent.getStringExtra("coffeeType");
coffeeCup = intent.getStringExtra("coffeeCup");
pickUpDate = intent.getStringExtra("pickUpDate");
pickUpTime = intent.getStringExtra("pickUpTime");
userPhone = intent.getStringExtra("userPhone");
db = new DBAdapter(this);

txtUserPhone = (TextView) findViewById(R.id.userPhone);


txtDonutFlavour = (TextView) findViewById(R.id.donutFlavour);
txtDonutNumber = (TextView) findViewById(R.id.donutNumber);
txtDonutPrice = (TextView) findViewById(R.id.donutFlavourPrice);
txtCoffeeType = (TextView) findViewById(R.id.coffeeType);
txtCoffeeCup = (TextView) findViewById(R.id.coffeeCup);
txtCoffeePrice = (TextView) findViewById(R.id.coffeeTypePrice);
txtDate = (TextView) findViewById(R.id.pickUpDate);
txtTime = (TextView) findViewById(R.id.pickUpTime);
txtTotalAmt = (TextView) findViewById(R.id.totalAmt);
orderNow = (Button) findViewById(R.id.btnOrderNow);
backToPreviousPage = (Button) findViewById(R.id.btnBackToPrevious);

switch (donutFlavour){
case "Banana" : donutPrice = 2.50; donutItemId = "#DF01";
break;
case "Chocolate" : donutPrice = 3.00; donutItemId = "DF02";
break;
case "Almond" : donutPrice = 3.50; donutItemId = "DF03"; break;
case "Grape" : donutPrice = 4.00; donutItemId = "DF04"; break;
case "Cheese" : donutPrice = 3.50; donutItemId = "DF05"; break;
case "strawberry" : donutPrice = 3.50; donutItemId = "DF06";
break;
case "cola" : donutPrice = 3.00; donutItemId = "DF07"; break;
case "milk" : donutPrice = 2.50; donutItemId = "DF08"; break;
case "mint" : donutPrice = 3.00; donutItemId = "DF09";break;
}

switch (coffeeType){
case "Black" : coffePrice = 7.50; coffeeItemId = "CT01"; break;
case "Cream" : coffePrice = 9.80; coffeeItemId = "CT02";
break;
case "Sweetener" : coffePrice = 10.50; coffeeItemId = "CT03";
break;
}

intDonutNumber = Integer.parseInt(donutNumber);
intCoffeeCup = Integer.parseInt(coffeeCup);
donutTotal = intDonutNumber * donutPrice;
coffeeTotal = intCoffeeCup * coffePrice;
totalAmt = donutTotal + coffeeTotal;
totalAmt = Math.round(totalAmt*100.0)/100.0;

txtUserPhone.setText(userPhone);
txtDonutFlavour.setText(donutFlavour);
txtDonutNumber.setText(donutNumber);
txtCoffeeType.setText(coffeeType);
txtCoffeeCup.setText(coffeeCup);
txtDate.setText(pickUpDate);
txtTime.setText(pickUpTime);
txtDonutPrice.setText("RM" + donutPrice);
txtCoffeePrice.setText("RM"+ coffePrice);
txtTotalAmt.setText("" + totalAmt);
}

public void BackToOnlineBookingPage(View view){


Intent i;
i = new Intent(completeBookingPage.this , OnlineBookingPage.class);
i.putExtra("userPhone", userPhone);
startActivity(i);
}

public void generateTicket(View view){


Intent intent = getIntent();
Intent i;

String getdonutFlavour = intent.getStringExtra("donutFlavour");


String getdonutNumber = intent.getStringExtra("donutNumber");
String getcoffeeType = intent.getStringExtra("coffeeType");
String getcoffeeCup = intent.getStringExtra("coffeeCup");
String getpickUpDate = intent.getStringExtra("pickUpDate");
String getpickUpTime = intent.getStringExtra("pickUpTime");
String getUserPhone = intent.getStringExtra("userPhone");
String getdonutPrice = txtDonutPrice.getText().toString().trim();
String getcoffeePrice = txtCoffeePrice.getText().toString().trim();
String gettmtAmt = txtTotalAmt.getText().toString().trim();

Integer orderId = 0;
String strOrderId;
String userPhone = getUserPhone;
String donutFlavour = getdonutFlavour;
String donutNumber = getdonutNumber;
String coffeeType = getcoffeeType;
String coffeeCup = getcoffeeCup;
String pickUpDate = getpickUpDate;
String pickUpTime = getpickUpTime;
String donutPrice = getdonutPrice;
String coffeePrice = getcoffeePrice;
String totalAmt = gettmtAmt;
String itemId = "#" + donutItemId + " " + "#" + coffeeItemId;
String qtyOrdered = donutNumber + " " + coffeeCup;
//get the order date
Calendar calendar = Calendar.getInstance();
String orderDate =
DateFormat.getDateInstance().format(calendar.getTime()).trim();

db.open();
db.insertContactIntotblOrderItem(itemId, qtyOrdered);
db.close();

db.open();
Cursor c = db.getAllOrderContacts();
if(c.moveToFirst()){
do{
orderId = c.getInt(0);
}while(c.moveToNext());
}

db.insertContactIntotblOrder(userPhone, orderId, orderDate,


pickUpDate, pickUpTime, totalAmt);
strOrderId = String.valueOf(orderId);
db.close();

i = new Intent(completeBookingPage.this, generateTicket.class);


i.putExtra("orderId", strOrderId);
i.putExtra("userPhone",userPhone);
i.putExtra("donutFlavour",donutFlavour);
i.putExtra("donutNumber",donutNumber);
i.putExtra("coffeeType",coffeeType);
i.putExtra("coffeeCup",coffeeCup);
i.putExtra("pickUpDate",pickUpDate);
i.putExtra("pickUpTime",pickUpTime);
i.putExtra("donutPrice",donutPrice);
i.putExtra("coffeePrice",coffeePrice);
i.putExtra("totalAmt",totalAmt);
startActivity(i);
}

XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".completeBookingPage">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:text="Phone : "
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.035"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/userPhone"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginTop="88dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.655"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Confirm Your Order"
android:textColor="@color/black"
android:textSize="40dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.492"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="172dp"
android:text="Donut"
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.039"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coffeeCup"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="376dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="472dp"
android:text="Schedule date and time"
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.135"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="520dp"
android:text="***Date"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.04"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="556dp"
android:text="***Time"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.043"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/pickUpDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="524dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnBackToPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="640dp"
android:background="@drawable/custom_edit_text"
android:onClick="BackToOnlineBookingPage"
android:text="Back"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnOrderNow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="640dp"
android:background="@drawable/custom_edit_text"
android:onClick="generateTicket"
android:text="Order NOW"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.234"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="336dp"
android:text="***type"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.042"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/totalAmt"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="424dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.963"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="296dp"
android:text="Coffee"
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.037"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="212dp"
android:text="***flavour"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.046"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coffeeTypePrice"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="340dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.963"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/donutFlavourPrice"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="216dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.963"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/donutFlavour"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="216dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="368dp"
android:text="***cup"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.042"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="416dp"
android:text="Total(RM) ******** "
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.055"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coffeeType"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="340dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/donutNumber"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="260dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/pickUpTime"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="556dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="252dp"
android:text="***number"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.046"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java : Generate ticket


package com.example.gonutsapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import android.widget.Button;
import android.widget.TextView;

public class generateTicket extends AppCompatActivity {

String orderId, donutFlavour, donutNumber, coffeeType, coffeeCup,


pickUpDate, pickUpTime, userPhone, donutPrice, coffeePrice, totalAmt;
TextView txtUserPhone, txtDonutFlavour, txtDonutNumber, txtDonutPrice;
TextView txtCoffeeType, txtCoffeeCup, txtCoffeePrice;
TextView txtDate, txtTime, txtTotalAmt, txtOrderId;
Button orderAgain;
Intent i;
DBAdapter db;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generate_ticket);
Intent intent = getIntent();
donutFlavour = intent.getStringExtra("donutFlavour");
donutNumber = intent.getStringExtra("donutNumber");
coffeeType = intent.getStringExtra("coffeeType");
coffeeCup = intent.getStringExtra("coffeeCup");
pickUpDate = intent.getStringExtra("pickUpDate");
pickUpTime = intent.getStringExtra("pickUpTime");
userPhone = intent.getStringExtra("userPhone");
donutPrice = intent.getStringExtra("donutPrice");
coffeePrice = intent.getStringExtra("coffeePrice");
totalAmt = intent.getStringExtra("totalAmt");
orderId = intent.getStringExtra("orderId");
db = new DBAdapter(this);

txtUserPhone = (TextView) findViewById(R.id.userPhone);


txtDonutFlavour = (TextView) findViewById(R.id.donutFlavour);
txtDonutNumber = (TextView) findViewById(R.id.donutNumber);
txtDonutPrice = (TextView) findViewById(R.id.donutFlavourPrice);
txtCoffeeType = (TextView) findViewById(R.id.coffeeType);
txtCoffeeCup = (TextView) findViewById(R.id.coffeeCup);
txtCoffeePrice = (TextView) findViewById(R.id.coffeeTypePrice);
txtDate = (TextView) findViewById(R.id.pickUpDate);
txtTime = (TextView) findViewById(R.id.pickUpTime);
txtTotalAmt = (TextView) findViewById(R.id.totalAmt);
txtOrderId = (TextView) findViewById(R.id.orderID);
orderAgain = (Button) findViewById(R.id.btnBackToMenu);

txtOrderId.setText(" #" + orderId);


txtUserPhone.setText(userPhone);
txtDonutFlavour.setText(donutFlavour);
txtDonutNumber.setText(donutNumber);
txtDonutPrice.setText(donutPrice);
txtCoffeeType.setText(coffeeType);
txtCoffeeCup.setText(coffeeCup);
txtCoffeePrice.setText(coffeePrice);
txtDate.setText(pickUpDate);
txtTime.setText(pickUpTime);
txtTotalAmt.setText(totalAmt);
}
public void orderAgain(View view){
i = new Intent(generateTicket.this, LoginSucceed.class);
i.putExtra("userPhone", userPhone);
startActivity(i);
}

XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".generateTicket">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:text="Phone : "
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.035"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/userPhone"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginTop="88dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.655"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/orderID"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textColor="@color/black"
android:textSize="40dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.933"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Order ID "
android:textColor="@color/black"
android:textSize="40dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.275"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="172dp"
android:text="Donut"
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.039"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="296dp"
android:text="Coffee"
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.031"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/pickUpDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="524dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.471"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="556dp"
android:text="***Time"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.038"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/donutNumber"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="260dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.471"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coffeeType"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="340dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.471"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/pickUpTime"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="556dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.471"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="336dp"
android:text="***type"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.037"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/donutFlavour"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="216dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.471"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/donutFlavourPrice"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="216dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.957"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/totalAmt"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="424dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.957"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coffeeCup"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="376dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.471"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="520dp"
android:text="***Date"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.034"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="368dp"
android:text="***cup"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.036"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="416dp"
android:text="Total(RM) ******** "
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.041"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="212dp"
android:text="***flavour"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.046"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="472dp"
android:text="Schedule date and time"
android:textSize="30dp"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.114"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/coffeeTypePrice"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="344dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.951"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="252dp"
android:text="***number"
android:textSize="20dp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.04"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btnBackToMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="636dp"
android:background="@drawable/custom_edit_text"
android:onClick="orderAgain"
android:text="Back to Menu"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

You might also like