0% found this document useful (0 votes)
9 views

Demo Mobile Programming

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Demo Mobile Programming

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 126

Lab Sheet – 02

 Develop a Card Game in Android Studio:


Source Code:
MainActivity.java:
package edu.pims.gamecard;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

ImageView blackCardView, redCardView;

Button resetBtn, playBtn;

TextView mesgTextView;

int redCardNumber, blackCardNumber;

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

blackCardView = findViewById(R.id.blackCard);
redCardView = findViewById(R.id.redCard);
resetBtn = findViewById(R.id.BtnReset);
playBtn = findViewById(R.id.BtnPlay);
mesgTextView = findViewById(R.id.TxtDraw);
playBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
flipCard();
changeCard();
checkWin();
}
});
resetBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reset();
}
});
}
int randomNumber(){
Random radomNum = new Random();

int num = radomNum.nextInt(13)+1;


Log.d("random", num+"");
return num;
}
void flipCard(){
redCardNumber = randomNumber();
blackCardNumber = randomNumber();
}
void checkWin(){
String result ="";
Log.d("Result Red",redCardNumber+"");
Log.d("Result Black",blackCardNumber+"");
if(blackCardNumber > redCardNumber){
result ="Black Win !!";
}
else if (blackCardNumber==1 && redCardNumber!=1 ){
result = "Black Win !!";
}
else if (redCardNumber==1 && blackCardNumber!=1 ){
result = "Red Win !!";
}
else if(redCardNumber > blackCardNumber){
result = "Red Win !!";
}
else {
result = "Draw";
}
mesgTextView.setText(result);
}
void changeCard(){
int resource = getResources().getIdentifier("black"+blackCardNumber,
"drawable",getPackageName());
blackCardView.setImageResource(resource);

int resource2 = getResources().getIdentifier("red"+redCardNumber, "drawable",


getPackageName());
redCardView.setImageResource(resource2);
}
void reset (){
blackCardNumber = 0;
redCardNumber = 0;
changeCard();
mesgTextView.setText("");
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/casinobg"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:id="@+id/cardLayout"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="180dp"
android:weightSum="2">
<ImageView
android:id="@+id/blackCard"
android:contentDescription="@string/black_card_message"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/black0"
/>
<ImageView
android:id="@+id/redCard"
android:contentDescription="@string/red_card_message"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/red0"
/>
</LinearLayout>
<Button
android:id="@+id/BtnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/cardLayout"
android:layout_marginTop="10dp"
android:text="Play"
android:backgroundTint="@color/amber"
/>
<TextView
android:id="@+id/TxtDraw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="44sp"
android:textColor="@color/white"
android:layout_marginBottom="10dp"
/>
<Button
android:id="@+id/BtnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/cardLayout"
android:layout_alignParentEnd="true"
android:text="Reset"
android:backgroundTint="@color/red"
android:layout_marginRight="52dp"
android:layout_marginBottom="12dp"
/>
</RelativeLayout>
Output:

Figure 2.1: Card Game Started / Reshuffled

Figure 2.2: Black Wins


Figure 2.3: Red Wins

Figure 2.4: Card Game Draw


Lab Sheet – 03

 Develop a BMI Calculator using Android Studio:


Source Code:
MainActivity.java:
package edu.pims.bmicalculator;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

TextView weightValueText;
TextView ageValueText;
TextView increaseWeightButton;
TextView decreaseWeightButton;
TextView increaseAgeButton;
TextView decreaseAgeButton;
TextView calculateBtn;
TextView displayHeight;
SeekBar heightSeekBar;

int heightValue;
int weightValue;
int ageValue;

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

weightValueText = findViewById(R.id.weightText);
ageValueText = findViewById(R.id.ageText);
increaseWeightButton = findViewById(R.id.plusWeight);
decreaseWeightButton = findViewById(R.id.minusWeight);
increaseAgeButton = findViewById(R.id.plusAge);
decreaseAgeButton = findViewById(R.id.minusAge);
calculateBtn = findViewById(R.id.calcuulateBtn);
displayHeight = findViewById(R.id.displayHeight);
heightSeekBar = findViewById(R.id.seekBar);

heightValue = Integer.parseInt(displayHeight.getText().toString());
weightValue = Integer.parseInt(weightValueText.getText().toString());
ageValue = Integer.parseInt(ageValueText.getText().toString());

heightSeekBar.setOnSeekBarChangeListener(new
SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
String height = String.valueOf(progress);
displayHeight.setText(height);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
increaseWeightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
weightValue++;
weightValueText.setText(weightValue+"");
}
});
decreaseWeightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
weightValue--;
weightValueText.setText(weightValue+"");
}
});
increaseAgeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ageValue++;
ageValueText.setText(ageValue+"");
}
});
decreaseAgeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ageValue--;
ageValueText.setText(ageValue+"");
}
});
calculateBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
heightValue = Integer.parseInt(displayHeight.getText().toString());
weightValue = Integer.parseInt(weightValueText.getText().toString());
float heightinMeters = heightValue/100f;
float BMI = weightValue / (heightinMeters * heightinMeters);
Intent intent = new Intent(MainActivity.this, ResultActivity.class);
intent.putExtra("BMI_RESULT", BMI);
startActivity(intent);
}
});
}
}

ResultActivity.java:
package edu.pims.bmicalculator;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ResultActivity extends AppCompatActivity {

TextView bmiTypeText;
TextView bmiValuesText;
TextView bmiMessageText;
Button recalculateBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_result);

bmiTypeText = findViewById(R.id.bmiType);
bmiValuesText = findViewById(R.id.bmiValues);
bmiMessageText = findViewById(R.id.bmiMessage);
recalculateBtn = findViewById(R.id.btnReCalcualateAgain);

Intent intent = getIntent();


float BMI = intent.getFloatExtra("BMI_RESULT",0);
bmiValuesText.setText(String.format("%.2f",BMI));

DisplayBmiCategory(BMI);

recalculateBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recalcuate();
}
});
}
void DisplayBmiCategory(float BMI){
String bmiType;
String bmiMessage;
int color;

if(BMI < 18.5){


bmiType = "UNDERWEIGHT";
bmiMessage = "You are underweight. Please eat more!";
color = getResources().getColor(R.color.colorUnderWeight);
}
else if(BMI >= 18.5 && BMI <= 24.9){
bmiType = "NORMAL";
bmiMessage = "You are fit. Keep up the good work!";
color = getResources().getColor(R.color.colorNormal);
}
else if(BMI >= 25 && BMI <= 29.9){
bmiType = "OVERWEIGHT";
bmiMessage = "You are overweight. Exercise more!";
color = getResources().getColor(R.color.colorOverWeight);
}
else {
bmiType = "OBESE";
bmiMessage = "You are extremely unhealthy. Consult a doctor!";
color = getResources().getColor(R.color.colorObese);
}
bmiTypeText.setText(bmiType);
bmiTypeText.setTextColor(color);
bmiMessageText.setText(bmiMessage);
}
void recalcuate(){
Intent intent = new Intent(ResultActivity.this, MainActivity.class);
startActivity(intent);
}
}

activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/app"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:id="@+id/genderLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="210dp"
android:weightSum="2"
>
<androidx.cardview.widget.CardView
android:layout_width="170dp"
android:layout_height="170dp"
app:cardBackgroundColor="@color/card_bg"
android:layout_weight="1"
android:elevation="20dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="15dp"
app:cardCornerRadius="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="90dp"
android:layout_height="60dp"
android:src="@drawable/baseline_female_24"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:textColor="@color/white"
android:textSize="40dp"
android:textStyle="bold"
/>
</LinearLayout>

</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="170dp"
android:layout_height="170dp"
app:cardBackgroundColor="@color/card_bg"
android:layout_weight="1"
android:elevation="20dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="15dp"
app:cardCornerRadius="20dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">

<ImageView
android:layout_width="90dp"
android:layout_height="60dp"
android:src="@drawable/baseline_male_24"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textColor="@color/white"
android:textSize="40dp"
android:textStyle="bold"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>

</LinearLayout>

<androidx.cardview.widget.CardView
android:layout_below="@id/genderLayout"
android:id="@+id/sliderView"
android:layout_width="match_parent"
android:layout_height="170dp"
app:cardBackgroundColor="@color/card_bg"
android:layout_weight="1"
android:elevation="20dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="15dp"
app:cardCornerRadius="20dp">

<LinearLayout
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Height (CM)"
android:textColor="@color/white"
android:textSize="28sp"
android:textStyle="bold"
/>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
/>
<TextView
android:id="@+id/displayHeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="36sp"
android:text="169"
android:textColor="@color/white"
/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
/>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="169"
android:max="280"
android:progressBackgroundTint="@color/purple"
android:thumbTint="@color/red"
/>
</LinearLayout>

</androidx.cardview.widget.CardView>

<LinearLayout
android:id="@+id/anotherlayout"
android:layout_below="@id/sliderView"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="210dp"
android:weightSum="2">

<androidx.cardview.widget.CardView
android:layout_width="180dp"
android:layout_height="match_parent"
app:cardBackgroundColor="@color/card_bg"
android:layout_weight="1"
android:elevation="20dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="15dp"
app:cardCornerRadius="20dp"
>
<LinearLayout
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_height="20dp"
android:layout_width="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WEIGHT (KG)"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/weightText"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="69"
android:textColor="@color/white"
android:textSize="26sp"
android:textStyle="bold"
/>
<LinearLayout
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.cardview.widget.CardView
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
android:layout_gravity="center"
android:elevation="20dp"
>
<TextView
android:id="@+id/plusWeight"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="26sp"
android:textColor="@color/black"
android:textStyle="bold"
android:text="+"
/>
</androidx.cardview.widget.CardView>
<View
android:layout_width="11dp"
android:layout_height="wrap_content"
/>
<androidx.cardview.widget.CardView
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
android:elevation="20dp"
>
<TextView
android:id="@+id/minusWeight"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="26sp"
android:textColor="@color/black"
android:textStyle="bold"
android:text="-"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/nextview"
android:layout_width="170dp"
android:layout_height="170dp"
app:cardBackgroundColor="@color/card_bg"
android:layout_weight="1"
android:elevation="20dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="15dp"
app:cardCornerRadius="20dp"
>
<LinearLayout
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<View
android:layout_height="20dp"
android:layout_width="wrap_content"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AGE"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/ageText"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22"
android:textColor="@color/white"
android:textSize="26sp"
android:textStyle="bold"
/>
<LinearLayout
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.cardview.widget.CardView
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
android:elevation="20dp"
>
<TextView
android:id="@+id/plusAge"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="26sp"
android:textColor="@color/black"
android:textStyle="bold"
android:text="+"
/>

</androidx.cardview.widget.CardView>

<View
android:layout_width="11dp"
android:layout_height="wrap_content"
/>
<androidx.cardview.widget.CardView
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
android:elevation="20dp">
<TextView
android:id="@+id/minusAge"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="26sp"
android:textColor="@color/black"
android:textStyle="bold"
android:text="-"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="@color/red"
android:gravity="center">

<TextView
android:id="@+id/calcuulateBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:textColor="@color/white"
android:textSize="44sp"
android:textStyle="bold"
/>
</LinearLayout>
</RelativeLayout>

activity_result.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.cardview.widget.CardView
android:id="@+id/cardResult"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="100dp"
android:layout_marginHorizontal="20dp"
app:cardBackgroundColor="@color/card_bg">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/bmiType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NORMAL"
android:textColor="@color/textcolor"
android:textSize="44sp"
android:textStyle="bold"
/>
<View
android:layout_width="match_parent"
android:layout_height="20dp"
/>
<TextView
android:id="@+id/bmiValues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="22.2"
android:textSize="32sp"
android:textStyle="bold"
/>
<View
android:layout_width="match_parent"
android:layout_height="50dp"
/>
<TextView
android:id="@+id/bmiMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="Keep it Up!!!"
android:textSize="22sp"
android:textStyle="bold"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<Button
android:layout_below="@+id/cardResult"
android:layout_marginTop="28dp"
android:id="@+id/btnReCalcualateAgain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recalculate"
android:textSize="30sp"
android:textStyle="bold"
android:backgroundTint="@color/red"
/>
</RelativeLayout>
Output:

Figure 3.1: Interface of BMI Calculator

Figure 3.2: Showing Under -Weight in BMI Calculator


Figure 3.3: Showing Normal -Weight in BMI Calculator

Figure 3.4: Showing Over – Weight in BMI Calculator


Figure 3.5: Showing Obese – Weight in BMI Calculator
Lab Sheet – 04

 Develop a Business Card using Android Studio:


Source Code:
MainActivity.java
package edu.pims.businesscard;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

TextView nameTextView,
workTextView,
addressTextView,
emailTextView,
phoneTextView,
instaTextView,
fbTextView,
linkedinTextView;

TextView editName,
editWork,
editAddress,
editEmail,
editPhone,
editInsta,
editFb,
editLinkedin;
int EDIT_NAME =0;
int EDIT_WORK =1;
int EDIT_ADDRESS =2;
int EDIT_EMAIL =3;
int EDIT_PHONE =4;
int EDIT_INSTAGRAM =5;
int EDIT_FACEBOOK =6;
int EDIT_LINKEDIN =7;

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

//TextView
nameTextView = findViewById(R.id.nameText);
workTextView =findViewById(R.id.professionText);
addressTextView = findViewById(R.id.addressTextView);
emailTextView = findViewById(R.id.emailText);
phoneTextView = findViewById(R.id.contactText);
instaTextView = findViewById(R.id.instagramText);
fbTextView = findViewById(R.id.facebookText);
linkedinTextView = findViewById(R.id.linkedinText);

//EditTextViews
editName = findViewById(R.id.editName);
editWork = findViewById(R.id.editWork);
editAddress = findViewById(R.id.editAddress);
editEmail = findViewById(R.id.editEmail);
editPhone = findViewById(R.id.editPhone);
editInsta = findViewById(R.id.editInsta);
editFb = findViewById(R.id.editFb);
editLinkedin = findViewById(R.id.editLinkedin);

editName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",nameTextView.getText().toString());
intent.putExtra("code",EDIT_NAME);
startActivityForResult(intent,EDIT_NAME);
}
});
editWork.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",workTextView.getText().toString());
intent.putExtra("code",EDIT_WORK);
startActivityForResult(intent,EDIT_WORK);
}
});

editAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",addressTextView.getText().toString());
intent.putExtra("code",EDIT_ADDRESS);
startActivityForResult(intent,EDIT_ADDRESS);
}
});

editEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",emailTextView.getText().toString());
intent.putExtra("code",EDIT_EMAIL);
startActivityForResult(intent,EDIT_EMAIL);
}
});

editPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",phoneTextView.getText().toString());
intent.putExtra("code",EDIT_PHONE);
startActivityForResult(intent,EDIT_PHONE);
}
});

editInsta.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",instaTextView.getText().toString());
intent.putExtra("code",EDIT_INSTAGRAM);
startActivityForResult(intent,EDIT_INSTAGRAM);
}
});

editFb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",fbTextView.getText().toString());
intent.putExtra("code",EDIT_FACEBOOK);
startActivityForResult(intent,EDIT_FACEBOOK);
}
});

editLinkedin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditActivity.class);
intent.putExtra ("value",linkedinTextView.getText().toString());
intent.putExtra("code",EDIT_LINKEDIN);
startActivityForResult(intent,EDIT_LINKEDIN);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
super.onActivityResult(requestCode, resultCode,data);

if(requestCode==EDIT_NAME){
nameTextView.setText(data.getStringExtra("value"));
}
else if(requestCode==EDIT_WORK){
workTextView.setText(data.getStringExtra("value"));
}
else if (requestCode==EDIT_ADDRESS) {
addressTextView.setText(data.getStringExtra("value"));
}
else if (requestCode==EDIT_EMAIL) {
emailTextView.setText(data.getStringExtra("value"));
}
else if (requestCode==EDIT_PHONE) {
phoneTextView.setText(data.getStringExtra("value"));
}
else if (requestCode==EDIT_INSTAGRAM) {
instaTextView.setText(data.getStringExtra("value"));
}
else if (requestCode==EDIT_FACEBOOK) {
fbTextView.setText(data.getStringExtra("value"));
}
else if (requestCode==EDIT_LINKEDIN) {
linkedinTextView.setText(data.getStringExtra("value"));
}
}
}

EditActivity.java:
package edu.pims.businesscard;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class EditActivity extends AppCompatActivity {


public static final int NAME_EDIT_CODE = 0;
EditText editText;
Button button;
Intent intent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_edit);

editText = findViewById(R.id.editText);
button = findViewById(R.id.btnSubmit);

intent = getIntent();

renderParentData();
Intent intent =getIntent();
String value = intent.getStringExtra("value");
editText.setText(value);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent2 = new Intent();
int code = intent.getIntExtra("code",0);
intent2.putExtra("value",editText.getText().toString());
setResult(code,intent2);
finish();
}
});
}
void renderParentData(){
String value = intent.getStringExtra("value");
editText.setText(value);
}
}

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

<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_bg4"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout android:layout_gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_bg3"

android:gravity="center">

<View
android:layout_width="match_parent"
android:layout_height="70dp"/>

<androidx.cardview.widget.CardView
android:layout_width="155dp"
android:layout_height="155dp"
app:cardCornerRadius="250dp"
app:cardBackgroundColor="@color/white">
<androidx.cardview.widget.CardView
android:layout_width="150dp"
android:layout_height="150dp"
app:cardCornerRadius="250dp"
android:layout_gravity="center">

<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/changeable"
android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="25dp"/>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">

<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iconName"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/baseline_person_24"/>

<TextView
android:id="@+id/nameText"
android:layout_toRightOf="@id/iconName"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Bhavishya Sunuwar Rai"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/editName"
android:padding="5dp"
android:textColor="@color/app_bg3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="textEnd"
android:text="@string/edit"
android:background="@color/app_bg4"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="15dp"/>

<!-- Profession -->


<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">

<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iconProfession"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/baseline_laptop_24"/>

<TextView
android:id="@+id/professionText"
android:layout_toRightOf="@id/iconProfession"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Student"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/editWork"
android:padding="5dp"
android:textColor="@color/app_bg3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="textEnd"
android:text="@string/edit"
android:background="@color/app_bg4"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="15dp"/>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">
<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iconAddress"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/baseline_share_location_24"/>

<TextView
android:id="@+id/addressTextView"
android:layout_toRightOf="@id/iconAddress"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Tikathali"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/editAddress"
android:padding="5dp"
android:textColor="@color/app_bg3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="textEnd"
android:text="@string/edit"
android:background="@color/app_bg4"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="15dp"/>

<!-- Email -->


<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">

<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iconEmail"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/baseline_email_24"/>

<TextView
android:id="@+id/emailText"
android:layout_toRightOf="@id/iconEmail"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="[email protected]"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/editEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@color/app_bg4"
android:padding="5dp"
android:text="@string/edit"
android:textAlignment="textEnd"
android:textColor="@color/app_bg3"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="15dp"/>

<!-- Contact Number -->


<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">

<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iconContact"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/baseline_phone_24"/>

<TextView
android:id="@+id/contactText"
android:layout_toRightOf="@id/iconContact"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="+977-9828721525"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/editPhone"
android:padding="5dp"
android:textColor="@color/app_bg3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="textEnd"
android:text="@string/edit"
android:background="@color/app_bg4"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="15dp"/>

<!-- Instagram ID -->


<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">

<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iconInstagram"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:src="@drawable/baseline_instagram" />

<TextView
android:id="@+id/instagramText"
android:layout_toRightOf="@id/iconInstagram"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="bhavishya_sunuwar"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/editInsta"
android:padding="5dp"
android:textColor="@color/app_bg3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="textEnd"
android:text="@string/edit"
android:background="@color/app_bg4"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="15dp"/>

<!-- Facebook ID -->


<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">

<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iconFacebook"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/baseline_facebook"/>

<TextView
android:id="@+id/facebookText"
android:layout_toRightOf="@id/iconFacebook"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Bhavishya Sunuwar Rai"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/editFb"
android:padding="5dp"
android:textColor="@color/app_bg3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="textEnd"
android:text="@string/edit"
android:background="@color/app_bg4"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="15dp"/>

<!-- LinkedIn ID -->


<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_marginHorizontal="50dp"
android:layout_height="wrap_content">

<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iconLinkedIn"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentLeft="true"
android:src="@drawable/baseline_linkedin" />

<TextView
android:id="@+id/linkedinText"
android:layout_toRightOf="@id/iconLinkedIn"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="bhavishya_sunuwar"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/editLinkedin"
android:padding="5dp"
android:textColor="@color/app_bg3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:textAlignment="textEnd"
android:text="@string/edit"
android:background="@color/app_bg4"
android:layout_height="wrap_content"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>

<View
android:layout_width="match_parent"
android:layout_height="55dp"/>
</LinearLayout>
</ScrollView>

activity_edit.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_bg3"
android:orientation="vertical"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android">

<EditText
android:importantForAutofill="no"
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="25dp"
android:paddingVertical="16dp"
android:background="@color/white"
android:textColor="@color/black"
android:textAlignment="center"
android:textSize="24sp"
/>
<View
android:layout_width="match_parent"
android:layout_height="10dp"/>
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/app_bg4"
android:textColor="@color/app_bg3"
android:text="Submit"
android:padding="15dp"
/>
</LinearLayout>

Output:

Figure 4.1: Interface of Business Card


Figure 4.2: Editing Name in Business Card

Figure 4.3: Editing Profession in Business Card


Figure 4.4: Editing Address in Business Card

Figure 4.5: Editing Email in Business Card


Lab Sheet – 05

 Using different fragments using Android Studio:


Source Code:
MainActivity.java:
package edu.pims.chapter5;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
}
}
FirstFragment.java:
package edu.pims.chapter5;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class FirstFragment extends Fragment {

TextView result;
Button submit;
EditText num1,num2;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_first, container, false);
result = view.findViewById(R.id.result);
submit = view.findViewById(R.id.btn);
num1 = view.findViewById(R.id.firstNum);
num2 = view.findViewById(R.id.secondNum);

submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO
String firstnum = num1.getText().toString();
String secondnum = num2.getText().toString();
int num1 = Integer.parseInt(firstnum);
int num2 = Integer.parseInt(secondnum);
int show = num1+num2;
result.setText("The sum is: " + show);
}
});
return view;
}
}
SecondFragment.java:
package edu.pims.chapter5;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class SecondFragment extends Fragment {


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_second, container, false);
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="380dp"
android:weightSum="2"
>
<fragment
android:id="@+id/firstDisplayFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:name="edu.pims.chapter5.FirstFragment" />
<fragment
android:id="@+id/secondDisplayFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:name="edu.pims.chapter5.SecondFragment"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:textColor="@color/white"
android:textSize="22sp"
android:text="This is activity"
android:layout_gravity="center"
android:layout_height="wrap_content"
/>
</LinearLayout>
Fragment_first.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:background="@color/red"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:id="@+id/firstNum"
android:layout_width="match_parent"
android:layout_height="125dp"
android:hint="First number"
android:inputType="number">
</EditText>
<EditText
android:id="@+id/secondNum"
android:layout_width="match_parent"
android:layout_height="125dp"
android:hint="Second number"
android:inputType="number">
</EditText>

<Button
android:id="@+id/btn"
android:text="Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<TextView
android:layout_marginTop="32dp"
android:id="@+id/result"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>

</LinearLayout>
Fragment_second.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/blue"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".SecondFragment" >

<!-- TODO: Update blank fragment layout -->


<TextView
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="This is second Fragment"
/>
</RelativeLayout>
Output:

Figure 5.1: Interface of Fragments with Main Activity


Figure 5.2: Inserting Numbers to calculate in First Fragment

Figure 5.3: Result of calculation


Lab Sheet – 06

 To develop Meme Generator using Android Studio:


Source Code:
MainActivity.java:
package edu.pims.memegenerator;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

ImageView meme1, meme2, meme3, meme4, meme5, meme6, meme7, meme8;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
meme1 = findViewById(R.id.meme_one);
meme2 = findViewById(R.id.meme_two);
meme3 = findViewById(R.id.meme_three);
meme4 = findViewById(R.id.meme_four);
meme5 = findViewById(R.id.meme_five);
meme6 = findViewById(R.id.meme_six);
meme7 = findViewById(R.id.meme_seven);
meme8 = findViewById(R.id.meme_eight);

meme1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(1);
}
});

meme2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(2);
}
});

meme3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(3);
}
});

meme4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(4);
}
});

meme5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(5);
}
});

meme6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(6);
}
});

meme7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(7);
}
});

meme8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToGenerateMEMEScreen(8);
}
});
}

void goToGenerateMEMEScreen(int name){


Intent intent = new Intent(MainActivity.this, MemeGenerator.class);
intent.putExtra("drawableName", "meme"+name);
startActivity(intent);
}
}
MemeFragment.java:
package edu.pims.memegenerator;

import android.app.Activity;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

public class MemeFragment extends Fragment {

EditText editTopText, editBottomText;

public MemeFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_meme, container, false);
editTopText = view.findViewById(R.id.topTextEdit);
editBottomText = view.findViewById(R.id.bottomTextEdit);

editTopText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//TODO
Activity activity = getActivity();
if (activity instanceof MemeGenerator){
((MemeGenerator)getActivity()).updateTopText(s.toString());
}
}

@Override
public void afterTextChanged(Editable s) {
//do nothing
}
});

editBottomText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Activity activity = getActivity();
if (activity instanceof MemeGenerator){
((MemeGenerator)getActivity()).updateBottomText(s.toString());
}
}

@Override
public void afterTextChanged(Editable s) {
}
});
return view;
}
}
MemeGenerator.java:
package edu.pims.memegenerator;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MemeGenerator extends AppCompatActivity {


private static final int PERMISSION_REQUEST_CODE = 100;

TextView topTextView, bottomTextView;


ImageView memeImageView;
Button generateButton;
LinearLayout memeLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_meme_generator);
topTextView = findViewById(R.id.topTextView);
bottomTextView = findViewById(R.id.bottomTextView);
memeImageView = findViewById(R.id.memeImageView);
memeLayout = findViewById(R.id.memeLayout);
generateButton = findViewById(R.id.generateMemeBtn);

String drawableName = getIntent().getStringExtra("drawableName");

int resourceID = getResources().getIdentifier(drawableName, "drawable",


getPackageName());

memeImageView.setImageResource(resourceID);

generateButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

AlertDialog.Builder builder = new AlertDialog.Builder(MemeGenerator.this);


builder.setTitle("Saved to gallery");
builder.setMessage("Are you sure want to save this message to your gallery");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//TODO
generateMeme();
finish();
}
});

builder.setNegativeButton("No", new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which) {
//TODO
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
//Button to genereate meme and save in phone gallery
// generateMeme();
}
});
}
void updateTopText(String updateText){
topTextView.setText(updateText);
}
void updateBottomText(String updateText){
bottomTextView.setText(updateText);
}
void generateMeme(){
if (checkPermission()) {
saveLayoutToGallery();
} else {
requestPermission();
}
}

private boolean checkPermission() {


if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
int result = ContextCompat.checkSelfPermission(getApplicationContext(),
android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED;
} else {
return true;
}
}

private void requestPermission() {


if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
ActivityCompat.requestPermissions(this, new String[]
{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_REQUEST_CODE);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
saveLayoutToGallery();
} else {
Toast.makeText(this, "Permission Denied", Toast.LENGTH_SHORT).show();
}
}
}

private void saveLayoutToGallery() {


// the parent layout containing your TextViews and ImageView
Bitmap bitmap = getBitmapFromView(memeLayout);
saveBitmapToGallery(bitmap, this);
}
public Bitmap getBitmapFromView(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null) {
bgDrawable.draw(canvas);
} else {
canvas.drawColor(Color.WHITE);
}
view.draw(canvas);
return bitmap;
}

public void saveBitmapToGallery(Bitmap bitmap, Context context) {


String savedImagePath = null;

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",


Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + ".jpg";
File storageDir = new
File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURE
S) + "/memeGenerator");

if (!storageDir.exists()) {
storageDir.mkdirs();
}

File imageFile = new File(storageDir, imageFileName);


savedImagePath = imageFile.getAbsolutePath();

try {
OutputStream fOut = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.close();

MediaScannerConnection.scanFile(context, new String[]{imageFile.toString()}, null,


new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});

Toast.makeText(context, "Image saved to gallery!",


Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Failed to save image!", Toast.LENGTH_SHORT).show();
}
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MEME Generator"
android:textAlignment="center"
android:layout_marginVertical="15dp"
android:textStyle="bold"
android:textSize="32sp"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:weightSum="2"
>

<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>

<ImageView
android:id="@+id/meme_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/meme1"
android:scaleType="centerCrop"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>

<ImageView
android:id="@+id/meme_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/meme2"
android:scaleType="centerCrop"
/>
</androidx.cardview.widget.CardView>

</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:weightSum="2"
>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>
<ImageView
android:id="@+id/meme_three"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/meme3" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>

<ImageView
android:id="@+id/meme_four"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/meme4"
android:scaleType="centerCrop"
/>
</androidx.cardview.widget.CardView>

</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:weightSum="2"
>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/meme5"
android:scaleType="centerCrop"
android:id="@+id/meme_five"
/>
</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/meme6"
android:scaleType="centerCrop"
android:id="@+id/meme_six"
/>
</androidx.cardview.widget.CardView>

</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:weightSum="2"

>
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/meme7"
android:scaleType="centerCrop"
android:id="@+id/meme_seven"
/>
</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"
>

<ImageView
android:id="@+id/meme_eight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/meme8"
android:scaleType="centerCrop"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="100dp"/>
</LinearLayout>
</ScrollView>
activity_meme_generator.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<fragment
android:id="@+id/generateMeme"
android:name="edu.pims.memegenerator.MemeFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" />

<LinearLayout
android:id="@+id/memeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/white"
android:elevation="4dp"
android:padding="16dp"
android:layout_marginBottom="16dp">

<TextView
android:id="@+id/topTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:padding="16dp"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="16sp" />

<ImageView
android:id="@+id/memeImageView"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="fitXY"
android:src="@drawable/meme1" />

<TextView
android:id="@+id/bottomTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:padding="16dp"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>

<Button
android:id="@+id/generateMemeBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#51C0F3"
android:elevation="4dp"
android:text="Generate Meme"
android:textSize="18sp"
android:textStyle="bold" />

<View
android:layout_width="0dp"
android:layout_height="90dp"
/>
</LinearLayout>
</ScrollView>
fragment_meme.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#51C0F3"
android:padding="16dp"
android:gravity="center">

<EditText
android:id="@+id/topTextEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:hint="TOP TEXT"
android:padding="12dp"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="18sp"
android:layout_marginBottom="16dp" />

<EditText
android:id="@+id/bottomTextEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:hint="BOTTOM TEXT"
android:padding="12dp"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="18sp" />
</LinearLayout>
Output:

Figure 6.1: Interface of Meme Generator

Figure 6.2: Creating a Meme


Figure 6.3: Saving the generated meme

Figure 6.4: Saved Meme in Gallery


Lab Sheet – 07

 Developing menu for pizza using Android Studio:


Source Code:
MainActivity.java:
package edu.learn.pizzatown;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {


ImageView cheeseImg, mushroomImg, tomatoImg, oliveImg, basilImg, pineappleImg;

CheckBox checkboxCheese, checkboxMushroom, checkboxTomato, checkboxOlive,


checkboxBasil, checkboxPineapple;

Button orderButton;
boolean isCheeseChecked = false, isMushroomChecked = false, isTomatoChecked = false,
isOliveChecked = false, isBasilChecked = false, isPineappleChecked = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
cheeseImg = findViewById(R.id.cheese);
mushroomImg = findViewById(R.id.mushroom);
tomatoImg = findViewById(R.id.tomato);
oliveImg = findViewById(R.id.olive);
basilImg = findViewById(R.id.basil);
pineappleImg = findViewById(R.id.pineapple);

checkboxCheese = findViewById(R.id.checkCheese);
checkboxMushroom = findViewById(R.id.checkMushroom);
checkboxTomato = findViewById(R.id.checkTomato);
checkboxOlive = findViewById(R.id.checkOlive);
checkboxBasil = findViewById(R.id.checkBasil);
checkboxPineapple = findViewById(R.id.checkPineapple);
orderButton = findViewById(R.id.proceed);

checkboxCheese.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isCheeseChecked = isChecked;
if (isChecked) {
cheeseImg.setVisibility(View.VISIBLE);
} else {
cheeseImg.setVisibility(View.GONE);
}
}
});

checkboxMushroom.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isMushroomChecked = isChecked;
if (isChecked) {
mushroomImg.setVisibility(View.VISIBLE);
} else {
mushroomImg.setVisibility(View.GONE);
}
}
});

checkboxTomato.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isTomatoChecked = isChecked;
if (isChecked) {
tomatoImg.setVisibility(View.VISIBLE);
} else {
tomatoImg.setVisibility(View.GONE);
}
}
});

checkboxOlive.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isOliveChecked = isChecked;
if (isChecked) {
oliveImg.setVisibility(View.VISIBLE);
} else {
oliveImg.setVisibility(View.GONE);
}
}
});

checkboxBasil.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isBasilChecked = isChecked;
if (isChecked) {
basilImg.setVisibility(View.VISIBLE);
} else {
basilImg.setVisibility(View.GONE);
}
}
});

checkboxPineapple.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isPineappleChecked = isChecked;
if (isChecked) {
pineappleImg.setVisibility(View.VISIBLE);
} else {
pineappleImg.setVisibility(View.GONE);
}
}
});

orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, OrderActivity.class);
intent.putExtra("cheese", isCheeseChecked);
intent.putExtra("mushroom", isMushroomChecked);
intent.putExtra("tomato", isTomatoChecked);
intent.putExtra("olive", isOliveChecked);
intent.putExtra("basil", isBasilChecked);
intent.putExtra("pineapple", isPineappleChecked);
startActivity(intent);
}
});
//finish oncreate
}

public boolean onCreateOptionsMenu(Menu menu){


MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.pizza_town_menu,menu);
return true;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();

switch (id){
case R.id.magarita:
//do here
checkboxCheese.setChecked(true);
checkboxTomato.setChecked(true);
checkboxBasil.setChecked(true);
checkboxMushroom.setChecked(false);
checkboxOlive.setChecked(false);
checkboxPineapple.setChecked(false);
return true;

case R.id.topping:
//TODO
checkboxCheese.setChecked(true);
checkboxTomato.setChecked(true);
checkboxBasil.setChecked(false);
checkboxMushroom.setChecked(true);
checkboxOlive.setChecked(true);
checkboxPineapple.setChecked(false);
return true;

case R.id.newyork:
//TODO
checkboxCheese.setChecked(true);
checkboxTomato.setChecked(true);
checkboxBasil.setChecked(true);
checkboxMushroom.setChecked(true);
checkboxOlive.setChecked(true);
checkboxPineapple.setChecked(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
OrderActivity.java:
package edu.learn.pizzatown;

import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class OrderActivity extends AppCompatActivity {

TextView cheeseText, mushroomsText, tomatoText, oliveText, basilText, pineappleText;

Button backBtn, orderBtn;


Intent intent;
String[] quantity = {"One","Two","Three","Four","Five"};
Spinner typeSpinner;
Spinner quantitySpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_order);
cheeseText = findViewById(R.id.textCheese);
mushroomsText = findViewById(R.id.textMushroom);
tomatoText = findViewById(R.id.textTomato);
oliveText = findViewById(R.id.textOlive);
basilText = findViewById(R.id.textBasil);
pineappleText = findViewById(R.id.textPineapple);
backBtn = findViewById(R.id.btnBack);
orderBtn = findViewById(R.id.btnConfirm);
typeSpinner = findViewById(R.id.pizaSize);
quantitySpinner = findViewById(R.id.pizaQunanity);
registerForContextMenu(orderBtn);

typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
String type = parent.getItemAtPosition(position).toString();
Toast.makeText(OrderActivity.this,type,Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});

ArrayAdapter adapter = new ArrayAdapter(OrderActivity.this,


android.R.layout.simple_spinner_item,quantity);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_item);
quantitySpinner.setAdapter(adapter);

quantitySpinner.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
String type = parent.getItemAtPosition(position).toString();
Toast.makeText(OrderActivity.this,type,Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
renderIngrident();

backBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

orderBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// code here for popup menu.
showPopUpMenu(v);
}
});
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.first_context_menu,menu);
}

@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.singlelife:
//TODO
typeSpinner.setSelection(0);
quantitySpinner.setSelection(1);
return true;

case R.id.homeparty:
//TODO
typeSpinner.setSelection(2);
quantitySpinner.setSelection(3);
return true;
case R.id.officeparty:
//TODO
typeSpinner.setSelection(4);
quantitySpinner.setSelection(2);
return true;
}
return super.onContextItemSelected(item);
}

public void showPopUpMenu(View view){


PopupMenu popupMenu = new PopupMenu(OrderActivity.this,view);
popupMenu.inflate(R.menu.first_pop_up_menu);
popupMenu.setOnMenuItemClickListener(new
PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.dinein:
Toast.makeText(OrderActivity.this, "Your order has been placed for Dine
In",Toast.LENGTH_SHORT).show();
return true;
case R.id.takeaway:
Toast.makeText(OrderActivity.this, "Your order has been placed for Take
Aawy",Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
popupMenu.show();
}

void renderIngrident(){
intent = getIntent();
boolean isCheese = intent.getBooleanExtra("cheese",false);
if(isCheese){
cheeseText.setVisibility(View.VISIBLE);
}
boolean isMushrooms = intent.getBooleanExtra("mushroom",false);
if(isMushrooms){
mushroomsText.setVisibility(View.VISIBLE);
}
boolean isTomato = intent.getBooleanExtra("tomato",false);
if(isTomato){
tomatoText.setVisibility(View.VISIBLE);
}
boolean isOlive = intent.getBooleanExtra("olive",false);
if(isOlive){
oliveText.setVisibility(View.VISIBLE);
}
boolean isBasil = intent.getBooleanExtra("basil",false);
if(isBasil){
basilText.setVisibility(View.VISIBLE);
}
boolean isPineapple = intent.getBooleanExtra("pineapple",false);
if(isPineapple){
pineappleText.setVisibility(View.VISIBLE);
}
}
}
first_context_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/singlelife "
android:title="Single Life Rocks"
/>
<item android:id="@+id/homeparty "
android:title="Home Party"
/>
<item android:id="@+id/officeparty "
android:title="Office Party"
/>
</menu>
first_pop_up_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/dinein"
android:title="Right Now"
/>
<item
android:id="@+id/takeaway"
android:title="Take Away"
/>
</menu>
pizza_town_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="Magarita pizza"
android:id="@+id/magarita "
android:icon="@drawable/icon_fast_food"
app:showAsAction="always"
/>
<item
android:title="Mushroom Topping Pizza"
android:icon="@drawable/baseline_food_bank_24"
android:id="@+id/topping"
app:showAsAction="always"
/>
<item
android:title="New York Style pizza"
android:icon="@drawable/baseline_local_pizza_24"
android:id="@+id/newyork "
app:showAsAction="always"
/>
</menu>
Output:

Figure 7.1: Interface of Pizza Town


Figure 7.2: Toppings for Margarita Pizza

Figure 7.3: Toppings for Mushroom Pizza


Figure 7.4: Toppings for New York Style Pizza

Figure 7.5: After selecting “Proceed to Checkout Option”


Figure 7.6: Selecting the Size of Pizza

Figure 7.7: Selecting the Quantity of Pizza


Figure 7.8: Long Press in “Confirm” Button for Quantity Slice for Pizza

Figure 7.9: Single click in “Confirm” button show options


Figure 7.10: Clicking “Take Away”
Lab Sheet – 8

 Developing Burger Ordering application using Android Studio:


Source Code:
BurgerActivity.java:
package edu.pims.burgerapp;

import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class BurgerActivity extends AppCompatActivity {

RadioButton nonVegButton, vegButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// EdgeToEdge.enable(this);
setContentView(R.layout.activity_burger);
nonVegButton = findViewById(R.id.nonVegRadioBtn);
vegButton = findViewById(R.id.VegRadioBtn);
nonVegButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Fragment Called
NonVegBurgerFragment nonVegBurgerFragment = new
NonVegBurgerFragment();
//Framgment Manager
FragmentManager fragmentManager = getSupportFragmentManager();
//Fragment Transaction to transact fragment
FragmentTransaction transaction = fragmentManager.beginTransaction();
//Assigning layout with fragment
transaction.replace(R.id.burgerFrame,nonVegBurgerFragment);
//At last commit;
transaction.addToBackStack(null);
transaction.commit();
}
});
vegButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Fragment Called
VegBurgerFragment vegBurgerFragment = new VegBurgerFragment();
//Framgment Manager
FragmentManager fragmentManager = getSupportFragmentManager();
//Fragment Transaction to transact fragment
FragmentTransaction transaction = fragmentManager.beginTransaction();
//Assigning layout with fragment
transaction.replace(R.id.burgerFrame,vegBurgerFragment);
//At last commit;
transaction.addToBackStack(null);
transaction.commit();
}
});
}
}
NonVegBurgerFragment.java:
package edu.pims.burgerapp;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import android.text.Layout;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class NonVegBurgerFragment extends Fragment {
public NonVegBurgerFragment() {
// Required empty public constructor
}
LinearLayout saladLayout, baconLayout, cheeseLayout, meatLayout;
CardView addSalad, removeSalad, addBacon, removeBacon, addCheese, removeCheese,
addMeat, removeMeat;
AlertDialog alert;
Button orderButton;
TextView totalPriceText;
int bunPrice = 55;
int saladPrice = 10;
int baconPrice = 15;
int cheesePrice = 20;
int meatPrice = 25;
int totalPrice;
int saladCount = 0;
int baconCount = 0;
int cheeseCount = 0;
int meatCount = 0;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_non_veg_burger, container, false);
saladLayout = view.findViewById(R.id.saladLayout);
baconLayout = view.findViewById(R.id.baconLayout);
cheeseLayout = view.findViewById(R.id.cheeseLayout);
meatLayout = view.findViewById(R.id.meatLayout);
addSalad = view.findViewById(R.id.addSalad);
removeSalad = view.findViewById(R.id.removeSalad);
addBacon = view.findViewById(R.id.addBacon);
removeBacon = view.findViewById(R.id.removeBacon);
addCheese = view.findViewById(R.id.addCheese);
removeCheese = view.findViewById(R.id.removeCheese);
addMeat = view.findViewById(R.id.addMeat);
removeMeat = view.findViewById(R.id.removeMeat);
totalPriceText = view.findViewById(R.id.totalpriceText);
orderButton = view.findViewById(R.id.orderBtn);
addSalad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saladCount++;
changeSalad();
}
});
removeSalad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("saladCount", String.valueOf(saladCount));
saladCount--;
if (saladCount < 0) {
saladCount = 0;
}
changeSalad();
}
});
addBacon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
baconCount++;
changeBacon();
}
});
removeBacon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
baconCount--;
if (baconCount < 0) {
baconCount = 0;
}
changeBacon();
}
});
addCheese.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cheeseCount++;
changeCheese();
}
});
removeCheese.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cheeseCount--;
if (cheeseCount < 0) {
cheeseCount = 0;
}
changeCheese();
}
});
addMeat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
meatCount++;
changeMeat();
}
});
removeMeat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
meatCount--;
if (meatCount < 0) {
meatCount = 0;
}
changeMeat();
}
});
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Order Confirmation For Non-Veg Burger:");
builder.setCancelable(false);
LayoutInflater layoutInflater = getLayoutInflater();
View view1 = layoutInflater.inflate(R.layout.item_ordered_non_veg, null);

TextView saladQuantity = view1.findViewById(R.id.saladQuantity);


saladQuantity.setText(String.valueOf(saladCount));
TextView saladPriceText = view1.findViewById(R.id.salprice);
saladPriceText.setText(String.valueOf(saladCount*saladPrice));

TextView baconQuantity = view1.findViewById(R.id.baconQuantity);


baconQuantity.setText(String.valueOf(baconCount));
TextView baconPriceText = view1.findViewById(R.id.baconprice);
baconPriceText.setText(String.valueOf(baconCount*baconPrice));

TextView cheeseQuantity = view1.findViewById(R.id.cheeseQuantity);


cheeseQuantity.setText(String.valueOf(cheeseCount));
TextView cheesePriceText = view1.findViewById(R.id.cheeseprice);
cheesePriceText.setText(String.valueOf(cheeseCount*cheesePrice));

TextView meatQuantity = view1.findViewById(R.id.meatQuantity);


meatQuantity.setText(String.valueOf(meatCount));
TextView meatPriceText = view1.findViewById(R.id.meatprice);
meatPriceText.setText(String.valueOf(meatCount*meatPrice));
TextView totalPriceText = view1.findViewById(R.id.totalPrice);
totalPriceText.setText("Total Price:" + (bunPrice + totalPrice));
DatePicker datePicker = view1.findViewById(R.id.orderDate);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
datePicker.setOnDateChangedListener(new
DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int
dayOfMonth) {
Toast.makeText(getContext(), "Selected Date: " + dayOfMonth + "/" +
(monthOfYear + 1) + "/" + year, Toast.LENGTH_SHORT).show();
// Toast.makeText(getContext(), "", Toast.LENGTH_SHORT).show();
}
});
}
Button confirm = view1.findViewById(R.id.btnConfirm);
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth() + 1;
int year = datePicker.getYear();
String orderDate = day + "/" + month + "/" + year;
Toast.makeText(getActivity(), "Order confirmed on: " + orderDate,
Toast.LENGTH_SHORT).show();
alert.dismiss();
resetValues();
}
});
builder.setView(view1);
alert = builder.create();
alert.show();
//we will do custom dialog.
}
});
return view;
}
void changeSalad() {
saladLayout.removeAllViews();
for (int i = 0; i < saladCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.salad_shape);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
20,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
imgView.setLayoutParams(params);
saladLayout.addView(imgView);
}
updateTotalPrice();
}
void changeBacon() {
baconLayout.removeAllViews();
for (int i = 0; i < baconCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.bacon_shape);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
10,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
int marginInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
10, // Adjust the margin size as needed
getResources().getDisplayMetrics()
);
params.leftMargin = marginInPixels;
params.rightMargin = marginInPixels;
imgView.setLayoutParams(params);
baconLayout.addView(imgView);
}
updateTotalPrice();
}
void changeCheese() {
cheeseLayout.removeAllViews();
for (int i = 0; i < cheeseCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.cheese_shape);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
15,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
imgView.setLayoutParams(params);
cheeseLayout.addView(imgView);
}
updateTotalPrice();
}
void changeMeat() {
meatLayout.removeAllViews();
for (int i = 0; i < meatCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.meat_shape);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
35,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
imgView.setLayoutParams(params);
meatLayout.addView(imgView);
}
updateTotalPrice();
}
void updateTotalPrice() {
totalPrice = (saladCount * saladPrice) + (baconCount * baconPrice) + (cheeseCount *
cheesePrice) + (meatCount * meatPrice);
totalPriceText.setText(""+ (bunPrice + totalPrice));
}
private void resetValues() {
saladCount = 0;
baconCount = 0;
cheeseCount = 0;
meatCount = 0;
totalPrice = bunPrice;
updateTotalPrice();
saladLayout.removeAllViews();
baconLayout.removeAllViews();
cheeseLayout.removeAllViews();
meatLayout.removeAllViews();
}
}
VegBurgerFragment.java:
package edu.pims.burgerapp;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;

public class VegBurgerFragment extends Fragment {


public VegBurgerFragment() {
// Required empty public constructor
}
LinearLayout saladLayout, baconLayout, cheeseLayout, PattyLayout;
CardView addSalad, removeSalad, addCarrotBacon, removeCarrotBacon, addCheese,
removeCheese, addPatty, removePatty;
AlertDialog alert;
Button orderButton;
TextView totalPriceText;
int bunPrice = 55;
int saladPrice = 10;
int carrotBaconPrice = 10;
int cheesePrice = 20;
int PattyPrice = 15;
int totalPrice;
int saladCount = 0;
int carrotBaconCount = 0;
int cheeseCount = 0;
int PattyCount = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_veg_burger, container, false);
saladLayout = view.findViewById(R.id.saladLayout);
baconLayout = view.findViewById(R.id.baconLayout);
cheeseLayout = view.findViewById(R.id.cheeseLayout);
PattyLayout = view.findViewById(R.id.pattyLayout);
addSalad = view.findViewById(R.id.addSalad);
removeSalad = view.findViewById(R.id.removeSalad);
addCarrotBacon = view.findViewById(R.id.addBacon);
removeCarrotBacon = view.findViewById(R.id.removeBacon);
addCheese = view.findViewById(R.id.addCheese);
removeCheese = view.findViewById(R.id.removeCheese);
addPatty = view.findViewById(R.id.addPatty);
removePatty = view.findViewById(R.id.removePatty);
totalPriceText = view.findViewById(R.id.totalpriceText);
orderButton = view.findViewById(R.id.orderBtn);
addSalad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saladCount++;
changeSalad();
}
});
removeSalad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("saladCount", String.valueOf(saladCount));
saladCount--;
if (saladCount < 0) {
saladCount = 0;
}
changeSalad();
}
});
addCarrotBacon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
carrotBaconCount++;
changeBacon();
}
});
removeCarrotBacon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
carrotBaconCount--;
if (carrotBaconCount < 0) {
carrotBaconCount = 0;
}
changeBacon();
}
});
addCheese.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cheeseCount++;
changeCheese();
}
});
removeCheese.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cheeseCount--;
if (cheeseCount < 0) {
cheeseCount = 0;
}
changeCheese();
}
});
addPatty.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PattyCount++;
changePatty();
}
});
removePatty.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PattyCount--;
if (PattyCount < 0) {
PattyCount = 0;
}
changePatty();
}
});
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO Code
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Order Confirmation for Veg Burger:");
builder.setCancelable(false);
LayoutInflater layoutInflater = getLayoutInflater();
View view2 = layoutInflater.inflate(R.layout.item_ordered_veg, null);

TextView saladQuantity = view2.findViewById(R.id.VegsaladQuantity);


saladQuantity.setText(String.valueOf(saladCount));
TextView saladPriceText = view2.findViewById(R.id.vegsalprice);
saladPriceText.setText(String.valueOf(saladCount*saladPrice));

TextView carrotBaconQuantity = view2.findViewById(R.id.carrotbaconQuantity);


carrotBaconQuantity.setText(String.valueOf(carrotBaconCount));
TextView carrotBaconPriceText = view2.findViewById(R.id.carrotbaconprice);

carrotBaconPriceText.setText(String.valueOf(carrotBaconCount*carrotBaconPrice));

TextView cheeseQuantity = view2.findViewById(R.id.VegcheeseQuantity);


cheeseQuantity.setText(String.valueOf(cheeseCount));
TextView cheesePriceText = view2.findViewById(R.id.vegcheeseprice);
cheesePriceText.setText(String.valueOf(cheeseCount*cheesePrice));

TextView vegPattyQuantity = view2.findViewById(R.id.vegPattyQuantity);


vegPattyQuantity.setText(String.valueOf(PattyCount));
TextView vegPattyQuantityText = view2.findViewById(R.id.vegPattyprice);
vegPattyQuantityText.setText(String.valueOf(PattyCount*PattyPrice));

TextView totalPriceText = view2.findViewById(R.id.totalPrice);


totalPriceText.setText("Total Price: " + (bunPrice+totalPrice));
DatePicker datePicker = view2.findViewById(R.id.VegorderDate);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
datePicker.setOnDateChangedListener(new
DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int
dayOfMonth) {
Toast.makeText(getContext(), "Selected Date: " + dayOfMonth + "/" +
(monthOfYear + 1) + "/" + year, Toast.LENGTH_SHORT).show();
// Toast.makeText(getContext(), "", Toast.LENGTH_SHORT).show();
}
});
}
Button Confirm = view2.findViewById(R.id.btnConfirm);
Confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth() + 1;
int year = datePicker.getYear();
String orderDate = day + "/" + month + "/" + year;
Toast.makeText(getActivity(), "Order confirmed on: " + orderDate,
Toast.LENGTH_SHORT).show();
alert.dismiss();
resetValues();
}
});
builder.setView(view2);
alert = builder.create();
alert.show();
}
});
return view;
}
void changeSalad() {
saladLayout.removeAllViews();
for (int i = 0; i < saladCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.salad_shape);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
20,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
imgView.setLayoutParams(params);
saladLayout.addView(imgView);
}
updateTotalPrice();
}
void changeBacon() {
baconLayout.removeAllViews();
for (int i = 0; i < carrotBaconCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.carrot_bacon);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
10,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
int marginInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
10, // Adjust the margin size as needed
getResources().getDisplayMetrics()
);
params.leftMargin = marginInPixels;
params.rightMargin = marginInPixels;
imgView.setLayoutParams(params);
baconLayout.addView(imgView);
}
updateTotalPrice();
}
void changeCheese() {
cheeseLayout.removeAllViews();
for (int i = 0; i < cheeseCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.cheese_shape);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
15,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
imgView.setLayoutParams(params);
cheeseLayout.addView(imgView);
}
updateTotalPrice();
}
void changePatty() {
PattyLayout.removeAllViews();
for (int i = 0; i < PattyCount; i++) {
ImageView imgView = new ImageView(getActivity());
imgView.setBackgroundResource(R.drawable.veg_patty);
int heightInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
35,
getResources().getDisplayMetrics()
);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, // Width
heightInPixels // Height
);
imgView.setLayoutParams(params);
PattyLayout.addView(imgView);

}
updateTotalPrice();
}
void updateTotalPrice() {
totalPrice = (saladCount * saladPrice) + (carrotBaconCount * carrotBaconPrice) +
(cheeseCount * cheesePrice) + (PattyCount * PattyPrice);
totalPriceText.setText( ""+ (bunPrice + totalPrice));
}
private void resetValues(){
saladCount = 0;
carrotBaconCount = 0;
cheeseCount = 0;
PattyCount = 0;
totalPrice = bunPrice;
updateTotalPrice();
saladLayout.removeAllViews();
baconLayout.removeAllViews();
cheeseLayout.removeAllViews();
PattyLayout.removeAllViews();
}
}
activity_burger.xml:
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:contentDescription="@string/logo"
android:id="@+id/burger1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:src="@drawable/burger"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="@font/bungee_inline"
android:text="@string/welcome"
android:textSize="16sp"
android:textStyle="bold"
tools:ignore="RelativeOverlap" />
<ImageView
android:contentDescription="@string/logo"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:src="@drawable/burger"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:paddingVertical="9dp"
android:layout_marginVertical="10dp"
android:background="@color/dark_brown"
android:layout_height="wrap_content">
<TextView
android:id="@+id/burgerTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="@string/select_burger"
android:layout_marginHorizontal="9dp"
android:fontFamily="@font/bungee_inline"
/>
<RadioGroup
android:orientation="horizontal"
android:layout_below="@+id/burgerTitle"
android:layout_width="wrap_content"
android:paddingHorizontal="10dp"
android:layout_height="wrap_content">
<RadioButton
android:buttonTint="@color/white"
android:id="@+id/nonVegRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/non_veg"
android:textColor="@color/white"
android:fontFamily="@font/bungee_inline"
android:layout_marginHorizontal="10dp"
android:theme="@style/MyRadioButton"
/>
<RadioButton
android:buttonTint="@color/white"
android:id="@+id/VegRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/veg"
android:textColor="@color/white"
android:fontFamily="@font/bungee_inline"
android:theme="@style/MyRadioButton"
android:layout_marginHorizontal="10dp"
/>
</RadioGroup>
</RelativeLayout>
<FrameLayout
android:id="@+id/burgerFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
fragment_non_veg_burger.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".BurgerActivity">
<LinearLayout
android:id="@+id/burgerLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center">
<ImageView
android:contentDescription="@string/top_burger"
android:id="@+id/breadTop"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/burger_top" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed1"
android:layout_width="10dp"
android:layout_height="15dp"
android:background="@drawable/seeds"
android:layout_centerInParent="true"
android:layout_marginStart="24dp"
android:layout_marginTop="10dp"
android:rotation="-20" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed2"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="52dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="10" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed3"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="99dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="10" />
<ImageView
android:id="@+id/seed4"
android:contentDescription="@string/seed"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="152dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="-40" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed5"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="250dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="-50" />
<ImageView
android:id="@+id/seed6"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="300dp"
android:contentDescription="@string/seed"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="-60" />
<ImageView
android:id="@+id/seed7"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="360dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:contentDescription="@string/seed"
android:rotation="-60" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/saladLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:id="@+id/baconLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:id="@+id/cheeseLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:id="@+id/meatLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:background="@drawable/burger_bottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:contentDescription="@string/bottom_burger"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/prefLayout"
android:layout_below="@+id/burgerLayout"
android:layout_marginTop="50dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:background="#CF8F2E"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginVertical="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/current_price"
android:textSize="16sp"
android:textColor="@color/black"
android:textStyle="bold"
/>
<TextView
android:id="@+id/totalpriceText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bun_price"
android:textSize="16sp"
android:textColor="@color/black"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removeSalad"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/salad"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addSalad"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<View
android:layout_height="15dp"
android:layout_width="0dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removeBacon"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/bacon"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addBacon"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<View
android:layout_height="15dp"
android:layout_width="0dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removeCheese"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/cheese"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addCheese"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<View
android:layout_height="15dp"
android:layout_width="0dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removeMeat"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/meat"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addMeat"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<Button
android:id="@+id/orderBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order"
android:layout_marginTop="15dp"
android:backgroundTint="#C7C6C6"
android:textColor="@color/black"
android:layout_gravity="center"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_below="@+id/prefLayout"
android:layout_height="60dp"
/>
</RelativeLayout>
</ScrollView>
fragment_veg_burger.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".BurgerActivity">
<LinearLayout
android:id="@+id/burgerLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center">
<ImageView
android:contentDescription="@string/top_burger"
android:id="@+id/breadTop"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/burger_top" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed1"
android:layout_width="10dp"
android:layout_height="15dp"
android:background="@drawable/seeds"
android:layout_centerInParent="true"
android:layout_marginStart="24dp"
android:layout_marginTop="10dp"
android:rotation="-20" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed2"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="52dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="10" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed3"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="99dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="10" />
<ImageView
android:id="@+id/seed4"
android:contentDescription="@string/seed"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="152dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="-40" />
<ImageView
android:contentDescription="@string/seed"
android:id="@+id/seed5"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="250dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="-50" />
<ImageView
android:id="@+id/seed6"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="300dp"
android:contentDescription="@string/seed"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:rotation="-60" />
<ImageView
android:id="@+id/seed7"
android:layout_width="10dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginStart="360dp"
android:layout_marginTop="10dp"
android:background="@drawable/seeds"
android:contentDescription="@string/seed"
android:rotation="-60" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/saladLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:id="@+id/baconLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:id="@+id/cheeseLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:id="@+id/pattyLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:background="@drawable/burger_bottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:contentDescription="@string/bottom_burger"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/prefLayout"
android:layout_below="@+id/burgerLayout"
android:layout_marginTop="50dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:background="#CF8F2E"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginVertical="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/current_price"
android:textSize="16sp"
android:textColor="@color/black"
android:textStyle="bold"
/>
<TextView
android:id="@+id/totalpriceText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bun_price"
android:textSize="16sp"
android:textColor="@color/black"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removeSalad"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/salad"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addSalad"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<View
android:layout_height="15dp"
android:layout_width="0dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removeBacon"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/veg_bacon"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addBacon"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<View
android:layout_height="15dp"
android:layout_width="0dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removeCheese"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/cheese"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addCheese"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<View
android:layout_height="15dp"
android:layout_width="0dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/removePatty"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/remove"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="70dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_marginHorizontal="10dp"
android:text="@string/patty"
android:textStyle="bold"
/>
<androidx.cardview.widget.CardView
android:id="@+id/addPatty"
android:layout_width="40dp"
android:layout_height="40dp"
app:cardCornerRadius="40dp"
app:cardBackgroundColor="#8F5E1E"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add"
android:textColor="@color/white"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<Button
android:id="@+id/orderBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order"
android:layout_marginTop="15dp"
android:backgroundTint="#C7C6C6"
android:textColor="@color/black"
android:layout_gravity="center"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_below="@+id/prefLayout"
android:layout_height="60dp"
/>
</RelativeLayout>
</ScrollView>
item_ordered_non_veg.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_brown"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ingridents"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantity"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="18sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Salad"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/salad_shape"
/>
</LinearLayout>
<TextView
android:id="@+id/saladQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/salprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bacon"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/bacon_shape"
/>
</LinearLayout>
<TextView
android:id="@+id/baconQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/baconprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cheese"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/cheese_shape"
/>
</LinearLayout>
<TextView
android:id="@+id/cheeseQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/cheeseprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Meat"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/meat_shape"
/>
</LinearLayout>
<TextView
android:id="@+id/meatQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/meatprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TextView
android:id="@+id/totalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Price: "
android:textColor="@color/white"
android:textSize="16sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:id="@+id/btnConfirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm Your Order"
/>
<DatePicker
android:id="@+id/orderDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableLayout>
item_ordered_veg.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_brown"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ingridents"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantity"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="18sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Salad"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/salad_shape"
/>
</LinearLayout>
<TextView
android:id="@+id/VegsaladQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/vegsalprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carrot Bacon"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/carrot_bacon"
/>
</LinearLayout>
<TextView
android:id="@+id/carrotbaconQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/carrotbaconprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cheese"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/cheese_shape"
/>
</LinearLayout>
<TextView
android:id="@+id/VegcheeseQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/vegcheeseprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Veg Patty"
android:textColor="@color/white"
android:textSize="16sp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/veg_patty"
/>
</LinearLayout>
<TextView
android:id="@+id/vegPattyQuantity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@+id/vegPattyprice"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="0.0"
android:textColor="@color/white"
android:textSize="16sp"/>
</TableRow>
<TextView
android:id="@+id/totalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Price: "
android:textColor="@color/white"
android:textSize="16sp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:id="@+id/btnConfirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm Your Order"
/>
<DatePicker
android:id="@+id/VegorderDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableLayout>
Output:

Figure 8.1: Interface of Burger Town


Figure 8.2: Interface for Non-Veg Burger
Figure 8.3: Selecting items for ordering burger

Figure 8.4: Confirming order by selecting order date


Figure 8.5: Order Confirmation

Figure 8.6: Interface for Veg-Burger


Figure 8.7: Selecting items for burger

Figure 8.8: Selecting date to confirm order


Figure 8.9: Order Confirmation

You might also like