Experiment 6
Write an Android app For Registration Form
[Link]
package [Link];
import
import
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
public class MainActivity extends Activity implements OnClickListener{
EditText e1,e2,e3,e4;
TextView t1,t2,t3,t4,t5;
Button b1;
DatePicker dp;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
e1 = (EditText)findViewById([Link].editText1);
e2 = (EditText)findViewById([Link].editText2);
e3 = (EditText)findViewById([Link].editText3);
e4 = (EditText)findViewById([Link].editText4);
t1 = (TextView)findViewById([Link].textView1);
t2 = (TextView)findViewById([Link].textView2);
t3 = (TextView)findViewById([Link].textView3);
t4 = (TextView)findViewById([Link].textView4);
t5 = (TextView)findViewById([Link].textView5);
b1 = (Button)findViewById([Link].button1);
dp = (DatePicker)findViewById([Link].datePicker1);
[Link](this);
}
@Override
public void onClick(View v) {
String a = [Link]().toString();
String b = [Link]().toString();
String c = [Link]().toString();
String d = [Link]().toString();
int n1 = [Link]();
int n2 = [Link]();
int n3 = [Link]();
Intent in = new Intent(this,[Link]);
Bundle b2 = new Bundle();
[Link]("name",a);
[Link]("address",b);
[Link]("email",c);
[Link]("phone",d);
[Link]("num1",n1);
[Link]("num2",n2);
[Link]("num3",n3);
[Link](b2);
startActivity(in);
}
}
[Link]
package [Link];
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
public class DisplayActivity extends Activity {
TextView t1,t2,t3,t4,t5,t6;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_display);
t1 = (TextView)findViewById([Link].textView1);
t2 = (TextView)findViewById([Link].textView2);
t3 = (TextView)findViewById([Link].textView3);
t4 = (TextView)findViewById([Link].textView4);
t5 = (TextView)findViewById([Link].textView5);
t6 = (TextView)findViewById([Link].textView6);
b1 = (Button)findViewById([Link].button1);
Intent in = getIntent();
Bundle b3 = [Link]();
int i1 = [Link]("num1");
int i2 = [Link]("num2");
int i3 = [Link]("num3");
String a1 = [Link]("name");
String b1 = [Link]("address");
String c1 = [Link]("email");
String d1 = [Link]("phone");
String dob = i1+"/"+i2+"/"+i3;
[Link]("Name : " + a1);
[Link]("Address : " + b1);
[Link]("Email Id : " + c1);
[Link]("Phone Number : " + d1);
[Link](dob);
}
public void onClick(View v) {
Intent in1 = new Intent(this,[Link]);
startActivity(in1);
}
activity_main.xml
<LinearLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<ScrollView
android:layout_weight="30"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="166dp"
android:layout_height="wrap_content"
android:text="@string/n1"/>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/n2">
<requestFocus/>
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/n3"/>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/n2"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/n4"/>
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/n2"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/n6"/>
<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/n2"/>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/n5"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="40"
android:orientation="vertical">
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="30"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/n7"/>
</LinearLayout>
</LinearLayout>
activity_display.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".DisplayActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="58dp"
android:layout_marginTop="16dp"
android:text="@string/d1"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="32dp"
android:text="TextView"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="18dp"
android:text="TextView"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="23dp"
android:text="TextView"/>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_below="@+id/textView4"
android:layout_marginTop="27dp"
android:text="TextView"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView5"
android:layout_below="@+id/textView5"
android:layout_marginTop="28dp"
android:onClick="onClick"
android:text="@string/n8"/>
</RelativeLayout>
Ouput
Experiment 7
Write an Android program for Calculator App
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity implements OnClickListener {
EditText etNum1;
EditText etNum2;
Button
Button
Button
Button
btnAdd;
btnSub;
btnMult;
btnDiv;
TextView tvResult;
String oper = "";
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
etNum1 = (EditText) findViewById([Link].etNum1);
etNum2 = (EditText) findViewById([Link].etNum2);
btnAdd = (Button) findViewById([Link]);
btnSub = (Button) findViewById([Link]);
btnMult = (Button) findViewById([Link]);
btnDiv = (Button) findViewById([Link]);
tvResult = (TextView) findViewById([Link]);
[Link]((OnClickListener) this);
[Link](this);
[Link](this);
[Link](this);
}
@Override
public void onClick(View v) {
float num1 = 0;
float num2 = 0;
float result = 0;
num1 = [Link]([Link]().toString());
num2 = [Link]([Link]().toString());
switch ([Link]()) {
case [Link]:
oper = "+";
result = num1 + num2;
break;
case [Link]:
oper = "-";
result = num1 - num2;
break;
case [Link]:
oper = "*";
result = num1 * num2;
break;
case [Link]:
oper = "/";
result = num1 / num2;
break;
default:
break;
[Link](num1 + " " + oper + " " + num2 + " = " + result);
}
}
activity_main.xml
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1"
android:layout_marginLeft="10pt"
android:layout_marginRight="10pt"
android:layout_marginTop="3pt">
<EditText
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5pt"
android:id="@+id/etNum1"
android:layout_width="match_parent"
android:inputType="numberDecimal">
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5pt"
android:id="@+id/etNum2"
android:layout_width="match_parent"
android:inputType="numberDecimal">
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_marginTop="3pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="+"
android:textSize="8pt"
android:id="@+id/btnAdd">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="-"
android:textSize="8pt"
android:id="@+id/btnSub">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="*"
android:textSize="8pt"
android:id="@+id/btnMult">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="/"
android:textSize="8pt"
android:id="@+id/btnDiv">
</Button>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt"
android:textSize="12pt"
android:layout_marginTop="3pt"
android:id="@+id/tvResult"
android:gravity="center_horizontal">
</TextView>
</LinearLayout>
Output
10
11
Experiment 8
Write an Android app for Rating Bar
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity implements OnClickListener {
RatingBar ratingbar1;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
ratingbar1=(RatingBar)findViewById([Link].ratingBar1);
button=(Button)findViewById([Link].button1);
[Link](this);
}
@Override
public void onClick(View arg0) {
String rating=[Link]([Link]());
[Link](getApplicationContext(), rating,
Toast.LENGTH_LONG).show();
}
}
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"/>
<Button
12
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/ratingBar1"
android:layout_below="@+id/ratingBar1"
android:layout_marginLeft="92dp"
android:layout_marginTop="66dp"
android:text="submit"/>
</RelativeLayout>
Output
13
Experiment 9
Write an Android program for Time and Date Picker
[Link]
package [Link];
import
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
public class MainActivity extends Activity implements OnClickListener{
DatePicker dp;
Button b1;
TimePicker tp;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
dp = (DatePicker)findViewById([Link].datePicker1);
b1 = (Button)findViewById([Link].button1);
[Link](this);
tp = (TimePicker)findViewById([Link].timePicker1);
tp.setIs24HourView(true);
}
@Override
public void onClick(View arg0) {
int d1 = [Link]();
int d2 = [Link]() + 1;
int d3 = [Link]();
int d4 = [Link]();
int d5 = [Link]();
Intent in = new Intent(this,[Link]);
Bundle b1 = new Bundle();
[Link]("date", d1);
[Link]("month", d2);
[Link]("year", d3);
[Link]("hour", d4);
[Link]("minute", d5);
[Link](b1);
startActivity(in);
}
}
[Link]
14
package [Link];
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
public class TimeDateActivity extends Activity implements OnClickListener{
TextView t1,t2,t3,t4;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_time_date);
b1 = (Button)findViewById([Link].button1);
t1 = (TextView)findViewById([Link].textView1);
t2 = (TextView)findViewById([Link].textView2);
t3 = (TextView)findViewById([Link].textView3);
t4 = (TextView)findViewById([Link].textView4);
Intent in = getIntent();
Bundle b2 = [Link]();
int a = [Link]("date");
int b = [Link]("month");
int c = [Link]("year");
int d = [Link]("hour");
int e = [Link]("minute");
[Link]([Link](a)+"/"+[Link](b)
+"/"+[Link](c));
[Link](d + ":" + e);
[Link](this);
}
@Override
public void onClick(View v) {
Intent i = new Intent(this,[Link]);
startActivity(i);
}
activity_main.xml
<LinearLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
15
android:layout_height="match_parent"
android:orientation="vertical">
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="74dp"
android:layout_gravity="center"/>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:layout_gravity="center"
android:text="@string/d1"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
activity_time_date.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TimeDateActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="98dp"
android:layout_marginTop="47dp"
android:text="@string/d2"
android:layout_gravity="center"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
16
android:layout_marginTop="33dp"
android:text="@string/d3"
android:layout_gravity="center"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="117dp"
android:text="@string/back"
android:layout_gravity="center"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="26dp"
android:text="@string/t1"
android:layout_gravity="center"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="26dp"
android:text="@string/t2"
android:layout_gravity="center"/>
</RelativeLayout>
Output
17
18
Experiment 10
Write an android app for starting another activity using explicit
Intent
Main_activity.java
package [Link].ex_intent;
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
publicclass MainActivity extends ActionBarActivity {
Button b1;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
19
Navish();
}
publicvoid Navish()
{
b1=(Button)findViewById([Link].button1);
[Link](new [Link]() {
@Override
publicvoid onClick(View v) {
Intent i=new
Intent([Link],[Link]);
startActivity(i);
}
});
}
@Override
publicboolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate([Link], menu);
returntrue;
}
@Override
publicboolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
if (id == [Link].action_settings) {
returntrue;
}
[Link](item);
}
[Link]
package [Link].ex_intent;
import
import
import
import
[Link];
[Link];
[Link];
[Link];
publicclass Activity2 extends ActionBarActivity {
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_activity2);
}
}
20
acitivity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="[Link].ex_intent.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:text="activity 1"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_centerVertical="true"
android:text="Go"/>
</RelativeLayout>
activity_activity2.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="[Link].ex_intent.Activity2">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:text="Activity 2"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</RelativeLayout>
Output
21
Experiment 11
Write an android program to open a website using implicitIntent
[Link]
package [Link];
import
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
public class MainActivity extends Activity {
22
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
final EditText editText1=(EditText)findViewById([Link].editText1);
Button button1=(Button)findViewById([Link].button1);
[Link](new OnClickListener() {
}
}
@Override
public void onClick(View arg0) {
String url=[Link]().toString();
Intent intent=new Intent(Intent.ACTION_VIEW,[Link](url));
startActivity(intent);
}
});
activity_main.xml
<RelativeLayout xmlns:androclass="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="54dp"
android:text="Visit" />
</RelativeLayout>
Output
23
Experiment 12
Write an android program for Camera app
[Link]
package [Link];
import
import
import
import
import
24
[Link];
[Link];
[Link];
[Link];
[Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
imageView = (ImageView) [Link]([Link].imageView1);
Button photoButton = (Button) [Link]([Link].button1);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent([Link].ACTION_IMAG
E_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) [Link]().get("data");
[Link](photo);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link].activity_main, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:androclass="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
25
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Take a Photo" >
</Button>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button1"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" >
</ImageView>
</RelativeLayout>
Output
Experiment 13
Write an android program for Progress Bar
[Link]
package [Link].progressbar1;
import
import
import
import
import
import
26
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
Button btnStartProgress;
ProgressDialog progressBar;
private int progressBarStatus = 0;
private Handler progressBarHandler = new Handler();
private long fileSize = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick() {
btnStartProgress = (Button) findViewById([Link].button1);
[Link](new OnClickListener(){
@Override
public void onClick(View v) {
progressBar = new ProgressDialog([Link]());
[Link](true);
[Link]("File downloading ...");
[Link](ProgressDialog.STYLE_HORIZONTAL);
[Link](0);
[Link](100);
[Link]();
progressBarStatus = 0;
fileSize = 0;
new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {
progressBarStatus = doOperation();
try {
[Link](1000);
} catch (InterruptedException e) {
[Link]();
}
[Link](new Runnable() {
public void run() {
[Link](progressBarStatus);
}
});
if (progressBarStatus >= 100) {
27
try {
[Link](1000);
} catch (InterruptedException e)
{[Link]();}
[Link]();
}
}
});
}
}).start();
}
public int doOperation() {
while (fileSize <= 10000) {
fileSize++;
if (fileSize == 1000) {
return 10;
} else if (fileSize == 2000) {
return 20;
} else if (fileSize == 3000) {
return 30;
} else if (fileSize == 4000) {
return 40;
} else if (fileSize == 5000) {
return 50;
} else if (fileSize == 6000) {
return 60;
}
else if (fileSize == 7000) {
return 70;
}
else if (fileSize == 8000) {
return 80;
}
else if (fileSize == 9000) {
return 90;
}
else if (fileSize == 10000) {
return 100;
}
}
return 100;
}
}
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
28
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="46dp"
android:layout_marginTop="24dp"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar1"
android:layout_below="@+id/progressBar1"
android:layout_marginTop="46dp"
android:text="Button"/>
</RelativeLayout>
Output
Experiment 14
Write a android program for accelerometer Sensor
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
29
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
SensorManager sm = null;
TextView accText = null;
List list;
SensorEventListener sel = new SensorEventListener(){
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
float[] values = [Link];
[Link]("x: "+values[0]+"\ny: "+values[1]+"\nz: "+values[2]);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
sm = (SensorManager)getSystemService(SENSOR_SERVICE);
accText = (TextView)findViewById([Link].textView1);
list = [Link](Sensor.TYPE_ACCELEROMETER);
if([Link]()>0){
[Link](sel, (Sensor) [Link](0), SensorManager.SENSOR_DELAY_NORMAL);
}else{
[Link](getBaseContext(), "Error: No Accelerometer.", Toast.LENGTH_LONG);
}
}
@Override
protected void onStop() {
if([Link]()>0){
[Link](sel);
}
[Link]();
}
}
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
30
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="92dp"
android:layout_marginTop="114dp"
android:text="TextView"/>
</RelativeLayout>
Output
Experiment 15
Write an android program for Graphics app
[Link]
package [Link];
import
import
import
import
31
[Link];
[Link];
[Link];
[Link];
import
import
import
import
[Link];
[Link];
[Link];
[Link];
public class MainActivity extends Activity {
DemoView demoview;
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
demoview = new DemoView(this);
setContentView(demoview);
}
private class DemoView extends View{
public DemoView(Context context){
super(context);
}
@Override protected void onDraw(Canvas canvas) {
[Link](canvas);
Paint paint = new Paint();
[Link]([Link]);
[Link]([Link]);
[Link](paint);
[Link](false);
[Link]([Link]);
[Link](20, 20, 15, paint);
[Link](true);
[Link]([Link]);
[Link](60, 20, 15, paint);
[Link](false);
[Link]([Link]);
[Link](100, 5, 200, 30, paint);
[Link](-45);
[Link]([Link]);
[Link]("Graphics Rotation", 40, 180, paint);
[Link]();
}
}
activity_main.xml
<RelativeLayoutxmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
32
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>
</RelativeLayout>
Output
33
[Link].
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
34
Name
Enroll No.
Viva/File(5)
Exp. Exectution (5)
Viva/File(5)
Exp. Exectution (5)
Viva/File(5)
Exp. Exectution (5)
Viva/File(5)
Exp. Exectution (5)
Viva/File(5)
Exp. Exectution (5)
GUIDELINES FOR CONTINUOUS ASSESSMENT
Continuous Lab assessment sheet
Date of Experiment :
17.
18.
19.
20.
21.
22.
23.
24.
25.
Internal Lab Assessment (End Semester)
[Link] Enrollment No.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
35
Name
Lab
file(10
)
Attendance(10) Quiz(10) Viva(10)
Program with
Execution(10)
Tota
l
(50)
[Link]
Android Functions
arc function in c
Declaration :- void arc(int x, int y, int stangle, int endangle, int radius);
arc function is used to draw an arc with center (x,y) and stangle specifies starting angle, endangle
specifies the end angle and last parameter specifies the radius of the arc. arc function can also be used
to draw a circle but for that starting angle and end angle should be 0 and 360 respectively.
bar function in c
Declaration :- void bar(int left, int top, int right, int bottom);
Bar function is used to draw a 2-dimensional, rectangular filled in bar . Coordinates of left top and
right bottom corner are required to draw the bar. Left specifies the X-coordinate of top left corner, top
specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner,
bottom specifies the Y-coordinate of right bottom corner. Current fill pattern and fill color is used to
fill the bar. To change fill pattern and fill color use setfillstyle.
bar3d function in c
Declaration :- void bar3d(int left, int top, int right, int bottom, int depth, int topflag);
bar3d function is used to draw a 2-dimensional, rectangular filled in bar . Coordinates of left top and
right bottom corner of bar are required to draw the bar. left specifies the X-coordinate of top left
corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right
bottom corner, bottom specifies the Y-coordinate of right bottom corner, depth specifies the depth of
bar in pixels, topflag determines whether a 3 dimensional top is put on the bar or not ( if it is non-zero
then it is put otherwise not ). Current fill pattern and fill color is used to fill the bar. To change fill
pattern and fill color use setfillstyle.
36
circle function in c
Declaration :- void circle(int x, int y, int radius);
circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the
circle. The code given below draws a circle.
cleardevice function in c
Declaration :- void cleardevice();
cleardevice function clears the screen in graphics mode and sets the current position to (0,0). Clearing
the screen consists of filling the screen with current background color.
closegraph function in c
closegraph function closes the graphics mode, deallocates all memory allocated by graphics system
and restores the screen to the mode it was in before you called initgraph.
Declaration :- void closegraph();
drawpoly function in c
Drawpoly function is used to draw polygons i.e. triangle, rectangle, pentagon, hexagon etc.
Declaration :- void drawpoly( int num, int *polypoints );
num indicates (n+1) number of points where n is the number of vertices in a polygon, polypoints
points to a sequence of (n*2) integers . Each pair of integers gives x and y coordinates of a point on
the polygon. We specify (n+1) points as first point coordinates should be equal to (n+1) th to draw a
complete figure.
To understand more clearly we will draw a triangle using drawpoly, consider for example the array :int points[] = { 320, 150, 420, 300, 250, 300, 320, 150};
points array contains coordinates of triangle which are (320, 150), (420, 300) and (250, 300). Note
that last point(320, 150) in array is same as first. See the program below and then its output, it will
further clear your understanding.
ellipse function in c
Declarations of ellipse function :-void ellipse(int x, int y, int stangle, int endangle, int xradius, int
yradius);
37
Ellipse is used to draw an ellipse (x,y) are coordinates of center of the ellipse, stangle is the starting
angle, end angle is the ending angle, and fifth and sixth parameters specifies the X and Y radius of the
ellipse. To draw a complete ellipse strangles and end angle should be 0 and 360 respectively.
fillellipse function in c
Declaration of fillellipse function :-void fillellipse(int x, int y, int xradius, int yradius);
x and y are coordinates of center of the ellipse, xradius and yradius are x and y radius of ellipse
respectively.
fillpoly function in c
Fillpoly function draws and fills a polygon. It require same arguments as drawpoly.
Declaration :- void drawpoly( int num, int *polypoints );
For details of arguments see drawpoly.
fillpoly fills using current fill pattern and color which can be changed using setfillstyle
floodfill function
Declaration :- void floodfill(int x, int y, int border);
floodfill function is used to fill an enclosed area. Current fill pattern and fill color is used to fill the
area.(x, y) is any point on the screen if (x,y) lies inside the area then inside will be filled otherwise
outside will be filled,border specifies the color of boundary of area. To change fill pattern and fill
color use setfillstyle. Code given below draws a circle and then fills it.
getbkcolor function in c
getbkcolor function returns the current background color
Declaration : int getbkcolor();
e.g. color = getbkcolor(); // color is an int variable
if current background color is GREEN then color will be 2.
getdrivername function
getdrivername function returns a pointer to the current graphics driver.
getcolor function
getcolor function returns the current drawing color.
Declaration : int getcolor();
38
e.g. a = getcolor(); // a is an integer variable
if current drawing color is WHITE then a will be 15.
getdrivername function
getdrivername function returns a pointer to the current graphics driver
39