This is a demo program for pizza delivery. This app works on sms method of pizza delivery. We need to provide pizza providers contact number, customer’s name and telephone number.Now we can select shape of pizza, cheese contents and topping of pizza. After that we can place order.
1.Send SMS by Intent:
We used intent to send sms to given pizza delivery destination after clubbing all information on pizza.
2.RadioGroup:
RadioGroup is used for combining two or more radio button for selecting one of those options. As we have two different requirements of RadioGroup one for selecting pizza shape and other for cheese content, we used to RadioGroup.
3.CheckBox:
CheckBox is used for selecting multiple options. Here we have multiple options for topping of pizza, so we used CheckBox for selection.
4.EditText:
We have used EditText for receiving user inputs like phone number and name. We have used HINT service of EditText for displaying hint to user for inputting relevant information.
1.MainActivity.java
package com.example.pizzadelivery;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.content.Intent;
public class MainActivity extends Activity {
EditText
name,number,pizzanumber;
RadioGroup
RG1,RG2;
RadioButton
rbCheese,rb2xCheese,rbNone,rbSquare,rbRoundPizza;
CheckBox
cbPepperoni,cbMusharoom,cbVeggies,cbAnchoice;
Button
btnSms;
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name
= (EditText)findViewById(R.id.name);
number
=(EditText)findViewById(R.id.number);
pizzanumber
=(EditText)findViewById(R.id.pizzanumber);
RG1=
(RadioGroup)findViewById(R.id.rbg1);
rbCheese
=(RadioButton)findViewById(R.id.rbcheese);
rb2xCheese
=(RadioButton)findViewById(R.id.rb2xcheese);
rbNone
=(RadioButton) findViewById(R.id.rbnone);
RG2=
(RadioGroup)findViewById(R.id.rbg2);
rbSquare
=(RadioButton)findViewById(R.id.rbsquare);
rbRoundPizza
=(RadioButton)findViewById(R.id.rbroundpizza);
cbPepperoni=(CheckBox)findViewById(R.id.cbpepperoni);
cbMusharoom=(CheckBox)findViewById(R.id.cbmushrooms);
cbVeggies=(CheckBox)findViewById(R.id.cbveggies);
cbAnchoice=(CheckBox)findViewById(R.id.cbanchovis);
btnSms=(Button)findViewById(R.id.btnsms);
btnSms.setOnClickListener(new View.OnClickListener() {
@Override
public
void onClick(View v) {
//
TODO Auto-generated method stub
String
msg="";
msg+="Name =
"+name.getText()+"\n";
msg+="Number =
"+number.getText()+"\n";
int radioId1=RG1.getCheckedRadioButtonId();
int radioId2=RG2.getCheckedRadioButtonId();
if(rbCheese.getId()==radioId1)
msg+="Cheese
\n";
if(rb2xCheese.getId()==radioId1)
msg+="
2xCheese \n";
if(rbNone.getId()==radioId1)
msg+="
None \n ";
if(rbSquare.getId()==radioId2)
msg+="Square
\n";
if(rbRoundPizza.getId()==radioId2)
msg+="RoundPizza
\n";
if(cbPepperoni.isChecked())
msg+="
& Pepperoni";
if(cbMusharoom.isChecked())
msg+="
& Musharoom";
if(cbVeggies.isChecked())
msg+="
& Veggies";
if(cbAnchoice.isChecked())
msg+="
& Anchoice";
String
pizzano = pizzanumber.getText().toString();
if(pizzano.length()>0
&& msg.length()>0)
sendSmsByIntent(pizzano,
msg);
else
Toast.makeText(getBaseContext(),
"Please Enter All data carefully.", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(),
msg, Toast.LENGTH_SHORT).show();
}
});
}
private void
sendSmsByIntent(String phNumber,String message)
{
Uri
uri = Uri.parse("smsto: "+ phNumber);
Intent
intent = new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body",
message);
startActivity(intent);
}
@Override
public
boolean onCreateOptionsMenu(Menu menu) {
//
Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main,
menu);
return
true;
}
}
2.activity_main.xml:
<?xml version="1.0"
encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0ff0ff"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0ff0ff"
android:orientation="vertical" >
<EditText
android:id="@+id/pizzanumber"
android:layout_width="310dp"
android:layout_height="20dp"
android:background="#ffffff"
android:layout_margin="4dp"
android:hint="Enter Pizza
Contact Number"/>
<EditText
android:id="@+id/name"
android:layout_width="310dp"
android:layout_height="20dp"
android:background="#ffffff"
android:layout_margin="4dp"
android:hint="Enter Your
Name" />
<EditText
android:id="@+id/number"
android:layout_width="310dp"
android:layout_height="20dp"
android:background="#ffffff"
android:layout_margin="4dp"
android:hint="Enter Your
Phone Name"/>
<RadioGroup
android:id="@+id/rbg1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rbcheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textStyle="bold"
android:text="Cheese" >
</RadioButton>
<RadioButton
android:id="@+id/rb2xcheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textStyle="bold"
android:text="2 X Cheese" >
</RadioButton>
<RadioButton
android:id="@+id/rbnone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textStyle="bold"
android:text="None" >
</RadioButton>
</RadioGroup>
<RadioGroup
android:id="@+id/rbg2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#0000ff"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rbsquare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textStyle="bold"
android:text="Square" >
</RadioButton>
<RadioButton
android:id="@+id/rbroundpizza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textStyle="bold"
android:text="Round Pizza" >
</RadioButton>
</RadioGroup>
<CheckBox
android:id="@+id/cbpepperoni"
android:text="Pepperoni"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="#fff000"
android:layout_width="wrap_content"/>
<CheckBox
android:id="@+id/cbmushrooms"
android:text="Mushrooms"
android:layout_margin="4dp"
android:layout_height="wrap_content"
android:background="#fff000"
android:layout_width="wrap_content"/>
<CheckBox
android:id="@+id/cbveggies"
android:text="Veggies"
android:layout_margin="4dp"
android:layout_height="wrap_content"
android:background="#fff000"
android:layout_width="wrap_content"/>
<CheckBox
android:id="@+id/cbanchovis"
android:text="Anchoise"
android:layout_margin="4dp"
android:layout_height="wrap_content"
android:background="#fff000"
android:layout_width="wrap_content"/>
<Button
android:id="@+id/btnsms"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#00ff00"
android:text="SMS: Place
your order"/>
</LinearLayout>
</ScrollView>
Screen Shots:
Manoj Mimanshak Trainee at Sisoft Technologies Indirapuram Ghaziabad