Roger IMP Assignment1GoNut
Roger IMP Assignment1GoNut
Roger IMP Assignment1GoNut
<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;
//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";
DatabaseHelper DBHelper;
SQLiteDatabase db;
@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);
}
}
//---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;
}*/
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;
@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);
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();
}
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>
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_succeed);
Intent intent = getIntent();
userPhone = intent.getStringExtra("userPhone");
}
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>
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_online_booking_page);
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);
}
donutFlavour.setText(donutItem);
coffeeType.setText(coffeeItem);
donutNumber.setText(donutItem2);
}
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
pickUpDate.setText(dayOfMonth + "-" + (monthOfYear + 1) +
"-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
pickUpTime.setText(hourOfDay + ":" + minute);
}
}, mHour, mMinute, false);
timePickerDialog.show();
}
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);
}
}
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;
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>
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complete_booking_page);
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);
}
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());
}
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>
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;
@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);
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>