Sie sind auf Seite 1von 90

MOBILE APPLICATION DEVELOPMENT

P.SRI HARSHA

17MIS7170

2.List View
XML File:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/LView"
android:background="#d1d1d1"
android:orientation="vertical">

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listview"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:dividerHeight="10dp"
android:divider="#d1d1d1"/>

</LinearLayout>

Item_list_product XML File:


<?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="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#ffffff"
android:orientation="vertical">

<TextView
android:id="@+id/p_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PRODUCT NAME"
android:textColor="@color/colorPrimaryDark"
android:textSize="25dp" />

<TextView
android:id="@+id/p_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PRODUCT PRICE"
android:textColor="@color/colorAccent"
android:textSize="25dp" />

<TextView
android:id="@+id/p_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PRODUCT DESCRIPTION"
android:textColor="@color/colorPrimary"
android:textSize="25dp" />

</LinearLayout>

Product Java File:


package com.example.listview;

public class Product {


private int id;
private String name;
private int price;
private String description;

// constructor
public Product(int id, String name, int price, String description) {
this.id = id;
this.name = name;
this.price = price;
this.description = description;
}

//setter and getter

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public int getPrice() {


return price;
}

public void setPrice(int price) {


this.price = price;
}

public String getDescription() {


return description;
}

public void setDescription(String description) {


this.description = description;
}
}
Product_List_Adapter Java File:
package com.example.listview;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class ProductListAdapter extends BaseAdapter {


private Context mContext;
private List<Product> mProductList;

//constructor
public ProductListAdapter(Context mContext, List<Product> mProductList) {
this.mContext = mContext;
this.mProductList = mProductList;
}

@Override
public int getCount() {
return mProductList.size();
}

@Override
public Object getItem(int i) {
return mProductList.get(i);
}

@Override
public long getItemId(int i) {
return i;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View V = View.inflate(mContext,R.layout.item_product_list,null);
TextView pname = (TextView)V.findViewById(R.id.p_name);
TextView pprice = (TextView)V.findViewById(R.id.p_price);
TextView pdesc = (TextView)V.findViewById(R.id.p_desc);

pname.setText(mProductList.get(i).getName());
pprice.setText(String.valueOf(mProductList.get(i).getPrice())+ "$");
pdesc.setText(mProductList.get(i).getDescription());

V.setTag(mProductList.get(i).getId());
return V;
}
}

Main Activity Java File:


package com.example.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private ListView list;


private ProductListAdapter adapter;
private List<Product> mproductlist;

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

list = (ListView)findViewById(R.id.listview);
mproductlist = new ArrayList<>();

//Add sample list

mproductlist.add(new Product(101,"Samsung A50",15000, "Smart phone with all features"));


mproductlist.add(new Product(102,"Samsung A10",12000, "Smart phone with all features"));
mproductlist.add(new Product(103,"Samsung A30",14000, "Smart phone with all features"));
mproductlist.add(new Product(104,"Samsung Tab",15000, "Tab with all features"));
mproductlist.add(new Product(201,"Apple",150, "fruit per kg 150"));
mproductlist.add(new Product(202,"Mango",120, "fruit per kg 120"));
mproductlist.add(new Product(201,"Orange",50, "fruit per kg 50"));

adapter = new ProductListAdapter(getApplicationContext(),mproductlist);


list.setAdapter(adapter);

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(),"Product ID
"+view.getTag(),Toast.LENGTH_SHORT).show();
}
});
}
}

Home Page Home Page


Toast Message

MOBILE APPLICATION DEVELOPMENT

P.SRI HARSHA

17MIS7170

1)LINEAR LAYOUT EXAMPLE:

XML FILE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="30dp"
android:text="BLUE" />

<Button
android:id="@+id/red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="30dp"
android:text="RED" />

<Button
android:id="@+id/green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="30dp"
android:text="GREEN" />

</LinearLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.lineareg;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {


Button red,blue,green;
LinearLayout linear;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
red = findViewById(R.id.red);
blue=findViewById(R.id.blue);
green=findViewById(R.id.green);
linear =(LinearLayout)findViewById(R.id.linear);
red.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linear.setBackgroundColor(Color.RED);
}
});
blue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linear.setBackgroundColor(Color.BLUE);
}
});
green.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linear.setBackgroundColor(Color.GREEN);
}
});
}
}

OUTPUT:
MOBILE APPLICATION DEVELOPMENT

P.Sri Harsha
17MIS7170

1. Date Picker
XML File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="146dp"
android:layout_marginTop="170dp"
android:text="SELECT A DATE"
android:textColor="@color/colorAccent"></Button>

<TextView
android:id="@+id/Textview"
android:layout_width="297dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="87dp"
android:layout_marginTop="378dp"
android:text=""
android:textColor="@color/colorPrimaryDark"
android:textSize="25dp"
android:textStyle="bold|italic"></TextView>

</RelativeLayout>

Main Activity Java File:


package com.example.datepicker;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


Button selectDate;
TextView viewDate;
DatePickerDialog datePickerDialog;
int year;
int month;
int dayOfMonth;
Calendar calendar;

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

selectDate = (Button)findViewById(R.id.button);
viewDate = (TextView) findViewById(R.id.Textview);

selectDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
datePickerDialog = new DatePickerDialog(MainActivity.this, new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
viewDate.setText(dayOfMonth+"/"+month+"/"+year);
}
},0,0,0);
datePickerDialog.show();
}
});
}
}
MOBILE APPLICATION DEVELOPMENT

Name:P.Sri Harsha

Reg.no:17MIS7170

1)INTENT EXAMPLE:

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

<EditText
android:id="@+id/et"
android:layout_width="243dp"
android:layout_height="0dp"
android:layout_marginStart="96dp"
android:layout_marginTop="56dp"
android:layout_marginBottom="144dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/sendmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/sendmail"
android:layout_width="204dp"
android:layout_height="133dp"
android:layout_marginEnd="112dp"
android:layout_marginBottom="105dp"
android:background="#F44336"
android:onClick="sendmail"
android:text="SEND MAIL"
app:layout_constraintBottom_toTopOf="@+id/openbrowser"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et" />

<Button
android:id="@+id/openbrowser"
android:layout_width="204dp"
android:layout_height="0dp"
android:layout_marginBottom="96dp"
android:background="#8BC34A"
android:onClick="openbrowser"

android:text="OPEN BROWSER"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sendmail" />

</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.intenteg;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


EditText mailinput;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mailinput = (EditText) findViewById(R.id.et);
}

public void sendmail(View view) {


Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
String[]
array={"harshapolineni888@gmail.com","abcd@gmal.com"};
i.putExtra(Intent.EXTRA_EMAIL,array);
i.putExtra(Intent.EXTRA_SUBJECT,"Welcome to VI-AP University");
String msg = mailinput.getText().toString();
i.putExtra(Intent.EXTRA_TEXT,msg);
if(i.resolveActivity(getPackageManager())!=null){
startActivity(i);
}

public void openbrowser(View view) {


Intent n= new Intent();
n.setAction(Intent.ACTION_VIEW);
n.setData(Uri.parse("http://www.googl.com"));
if(n.resolveActivity(getPackageManager())!=null)
{
startActivity(n);
}

}
OUTPUT:
MOBILE APPLICATION DEVELOPMENT

Name:P.Sri Harsha

Reg.no:17MIS7170

1.LOGIN

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

<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="2dp"
android:layout_marginTop="33dp"
android:layout_marginEnd="2dp"
android:layout_marginBottom="35dp"
android:text="Enter Username"
app:layout_constraintBottom_toTopOf="@+id/et1"
app:layout_constraintEnd_toEndOf="@+id/et2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/et1"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/et1"
android:layout_width="223dp"
android:layout_height="51dp"
android:layout_marginStart="20dp"
android:layout_marginBottom="53dp"
android:background="#E1D3C9"
android:ems="10"
android:hint="Enter User Name"
android:inputType="textPersonName"
android:textColorHint="#F40505"

app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="28dp"
android:text="Enter your Password"
app:layout_constraintBottom_toTopOf="@+id/et2"
app:layout_constraintEnd_toEndOf="@+id/et2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et1" />

<EditText
android:id="@+id/et2"
android:layout_width="227dp"
android:layout_height="61dp"
android:layout_marginStart="21dp"
android:layout_marginBottom="40dp"
android:background="#E1D3C9"
android:ems="10"
android:hint="Enter Password"
android:textColorHint="#F80202"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView2" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="36dp"
android:layout_marginBottom="343dp"
android:background="#C10D56E8"
android:shadowColor="#F10505"
android:text="Login"
android:textColor="#F8050D"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/et2"
app:layout_constraintTop_toBottomOf="@+id/et2" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:

package com.example.logineg1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText username;
EditText passwd;
Button login;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText)findViewById(R.id.et1);
passwd = (EditText)findViewById(R.id.et2);
login = (Button)findViewById(R.id.button);
login.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
if
(("admin".equals(username.getText().toString()) &&
("test".equals(passwd.getText().toString()))) ||

"ADMIN".equals(username.getText().toString()) &&
("test".equals(passwd.getText().toString()))) {

Toast.makeText(getApplicationContext(), "LOGIN
SUCCESSFUL", Toast.LENGTH_LONG).show();
} else {

Toast.makeText(getApplicationContext(), "LOGIN INVALID",


Toast.LENGTH_LONG).show();
}
}

});
}
}

OUTPUT:
MOBILE APPLICATION
DEVELOPMENT

P.Sri
Harsha
17MIS71
70

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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="49dp"
android:layout_marginTop="69dp"
android:text="Enter the first name"
app:layout_constraintStart_toStartOf="pare
nt"
app:layout_constraintTop_toTopOf="parent"
/>

<EditText
android:id="@+id/editTextTextPersonNa
me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="11dp"
android:layout_marginTop="37dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="@+id/textView
"
app:layout_constraintTop_toBottomOf="@+id/textView"
/>

<Button
android:id="@+id/button"
android:layout_width="wrap_conten
t"
android:layout_height="wrap_conte
nt"
android:layout_marginTop="49dp"
android:layout_marginEnd="16dp"
android:text="Click here"
app:layout_constraintEnd_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="77dp"
android:layout_marginTop="273dp"
android:text="Welcome !! to Android"
app:layout_constraintStart_toStartOf="pare
nt"
app:layout_constraintTop_toTopOf="parent"
/>

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="65dp"
android:layout_marginTop="47dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button
"
app:srcCompat="@drawable/ic_launcher_background"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
MAIN ACTIVITY JAVA FILE:
package com.example.userinput1;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import
android.content.Context;
import android.os.Bundle;
import android.view.View;
import
android.widget.Button;
import
android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


public EditText
FName; public
Button display;

@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FName = (EditText)findViewById(R.id.editTextTextPersonName);
final String a =
FName.getText().toString(); display =
(Button)findViewById(R.id.button);
display.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "WELCOME TO ANDROID!!!is
your First Name \n" , Toast.LENGTH_LONG).show();
}
});
}
}
RESUME:

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

<TextView
android:id="@+id/textView"
android:layout_width="138dp"
android:layout_height="34dp"
android:layout_marginStart="98dp"
android:layout_marginTop="32dp"
android:layout_marginBottom="23dp"
android:text="Resume"
app:layout_constraintBottom_toTopOf="@+id/na
me"
app:layout_constraintStart_toStartOf="parent
" app:layout_constraintTop_toTopOf="parent"
/>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_conten
t"
android:layout_height="wrap_conte
nt"
android:layout_marginStart="23dp"
android:layout_marginTop="73dp"
android:layout_marginBottom="70dp
" android:text="Enter your name"
app:layout_constraintBottom_toBottomOf="@+id/textVie
w3" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView" />

<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="89dp"
android:layout_marginEnd="21dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="15dp"
android:layout_marginStart="23dp
"
android:layout_marginTop="179dp"
android:layout_marginEnd="21dp"
android:layout_marginBottom="180
dp"
android:text="FatherName"
app:layout_constraintBottom_toTopOf="@+id/department"
app:layout_constraintEnd_toEndOf="@+id/textView5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="21dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="pare
nt"
app:layout_constraintTop_toBottomOf="@+id/name" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginBottom="53dp"
android:text="MotherName"
app:layout_constraintBottom_toTopOf="@+id/textVie
w5" app:layout_constraintStart_toStartOf="parent"
/>

<EditText
android:id="@+id/mname"
android:layout_width="211dp"
android:layout_height="54dp"
android:layout_marginTop="234dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="179
dp" android:ems="10"
android:inputType="textPersonNam
e"
app:layout_constraintBottom_toTopOf="@+id/radioGro
up" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginBottom="10dp"
android:text="College/University"
app:layout_constraintBottom_toBottomOf="@+id/colle
ge" app:layout_constraintStart_toStartOf="parent"
/>

<EditText
android:id="@+id/college"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="29dp"
android:layout_marginEnd="20dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="pare
nt"
app:layout_constraintTop_toBottomOf="@+id/mname" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="31dp"
android:layout_marginTop="42dp"
android:text="Department"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5"
/>

<EditText
android:id="@+id/department"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="21dp"
android:layout_marginEnd="23dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="pare
nt"
app:layout_constraintTop_toBottomOf="@+id/college" />

<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="45dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="91dp"
android:text="Gender"
app:layout_constraintEnd_toEndOf="@+id/textView6"
app:layout_constraintEnd_toStartOf="@+id/radioGrou
p" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="140dp"
android:layout_height="55dp"
android:layout_marginEnd="145dp"
android:layout_marginBottom="213dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textVie
w7"
app:layout_constraintTop_toBottomOf="@+id/mname"
>

<RadioButton
android:id="@+id/rb1"
android:layout_width="match_paren
t"
android:layout_height="wrap_conte
nt" android:text="Male" />

<RadioButton
android:id="@+id/rb2"
android:layout_width="match_paren
t"
android:layout_height="wrap_conte
nt" android:text="Female" />
</RadioGroup>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="84dp"
android:layout_marginEnd="20dp"
android:text="Create Resume"
app:layout_constraintEnd_toEndOf="@+id/radioGro
up"
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />

</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.resume;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.RadioButton;
import
android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

public EditText
n,fn,mn,dept,coll; Button b1;
RadioGroup r1;
RadioButton
b2,b3;

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

n=(EditText)findViewById(R.id.name);
fn=(EditText)findViewById(R.id.fname);
mn=(EditText)findViewById(R.id.mname);
dept=(EditText)findViewById(R.id.department);
r1 = (RadioGroup)
findViewById(R.id.radioGroup);
coll=(EditText)findViewById(R.id.college);
b2 =
(RadioButton)findViewById(R.id.rb1);
b3 =
(RadioButton)findViewById(R.id.rb2);
b1 = (Button)
findViewById(R.id.button);
b1.setOnClickListener(new
View.OnClickListener() { @Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Your Name
:\n"+n, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Father Name
:\n"+fn, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Mother Name :\n"+mn,
Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Department
:\n"+dept, Toast.LENGTH_LONG).show();

Toast.makeText(getApplicationContext(), "College/University
:\n"+coll, Toast.LENGTH_LONG).show();
int n=r1.getCheckedRadioButtonId();
RadioButton
rb1=(RadioButton)findViewById(n); if
(b2.isChecked()) {
Toast.makeText(MainActivity.this, "Gender: Male
\n",Toast.LENGTH_LONG).show();
}
else if(b3.isChecked()) {
Toast.makeText(MainActivity.this, "Gender: Female
\n",
Toast.LENGTH_LONG).show();
}

}
});
}
}
MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="36dp"
android:text="CURRENCY CONVERTER"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:textSize="50" />
<EditText
android:id="@+id/editTextNumberDecimal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="31dp"
android:ems="10"
android:hint="Enter Indian Rupee"
android:inputType="numberDecimal"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:textSize="20" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="82dp"
android:layout_marginTop="27dp"
app:layout_constraintStart_toStartOf="@+id/editTextNumberDecimal"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberDecimal">

<RadioButton
android:id="@+id/radioButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="USD" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="EURO" />

<RadioButton
android:id="@+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YEN" />
</RadioGroup>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="104dp"
android:layout_marginTop="48dp"
android:onClick="convertmethod"
android:text="CONVERT"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup"
tools:textSize="30" />
<EditText
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="77dp"
android:layout_marginTop="39dp"
android:ems="10"
android:inputType="numberDecimal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
tools:textSize="20" />

</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.currency;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText e1,e2;
RadioGroup r1;
RadioButton b2,b3,b4;
Button b1;

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

e1=findViewById(R.id.editTextNumberDecimal);
e2=findViewById(R.id.result);
b2=findViewById(R.id.radioButton3);
b3=findViewById(R.id.radioButton2);
b4=findViewById(R.id.radioButton);
b1=findViewById(R.id.button);
r1=findViewById(R.id.radioGroup);

}
public void convertmethod(View view){
float a = Float.parseFloat(e1.getText().toString());
if(b2.isChecked()){
float b = (float) (a*73.98);
e2.setText(String.valueOf(b));
}

else if (b3.isChecked()){
float b = (float) (a*87.48);
e2.setText(String.valueOf(b));
}

else if (b4.isChecked()){
float b = (float) (a*1.42);
e2.setText(String.valueOf(b));
}

else {
Toast.makeText(this, "Select any option to convert",
Toast.LENGTH_SHORT).show();
}
}

Home Page USD Conversion


EURO Conversion YEN Conversion

MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

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

<ImageView
android:id="@+id/imageView2"
android:layout_width="241dp"
android:layout_height="246dp"
android:layout_marginStart="4dp"
android:layout_marginBottom="532dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/a" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="182dp"
android:layout_height="0dp"
android:layout_marginStart="244dp"
android:layout_marginTop="28dp"
android:layout_marginBottom="184dp"
app:layout_constraintBottom_toTopOf="@+id/imageView5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.531"
app:srcCompat="@drawable/e" />

<ImageView
android:id="@+id/imageView4"
android:layout_width="398dp"
android:layout_height="0dp"
android:layout_marginTop="156dp"
android:layout_marginBottom="203dp"
app:layout_constraintBottom_toTopOf="@+id/imageView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/b" />

<ImageView
android:id="@+id/imageView5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="165dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView3"
app:srcCompat="@drawable/c" />

<ImageView
android:id="@+id/imageView6"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView4"
app:srcCompat="@drawable/d" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE


package com.example.display5images;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

2. CHANGE APP ICON


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

<ImageView
android:id="@+id/imageView2"
android:layout_width="241dp"
android:layout_height="246dp"
android:layout_marginStart="4dp"
android:layout_marginBottom="532dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/a" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="182dp"
android:layout_height="0dp"
android:layout_marginStart="244dp"
android:layout_marginTop="28dp"
android:layout_marginBottom="184dp"
app:layout_constraintBottom_toTopOf="@+id/imageView5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.531"
app:srcCompat="@drawable/e" />

<ImageView
android:id="@+id/imageView4"
android:layout_width="398dp"
android:layout_height="0dp"
android:layout_marginTop="156dp"
android:layout_marginBottom="203dp"
app:layout_constraintBottom_toTopOf="@+id/imageView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/b" />

<ImageView
android:id="@+id/imageView5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="165dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView3"
app:srcCompat="@drawable/c" />

<ImageView
android:id="@+id/imageView6"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView4"
app:srcCompat="@drawable/d" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE


package com.example.display5images;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

ANDROID MANIFEST XML FILE


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.display5images">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>
BEFORE ICON CHANGE AFTER ICON CHANGE

MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

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

<Button
android:id="@+id/btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="326dp"
android:text="9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:text="8"
app:layout_constraintBaseline_toBaselineOf="@+id/btn7"
app:layout_constraintStart_toEndOf="@+id/btn9" />

<Button
android:id="@+id/btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginEnd="24dp"
android:text="7"
app:layout_constraintEnd_toStartOf="@+id/btndiv"
app:layout_constraintTop_toTopOf="@+id/btn9" />

<Button
android:id="@+id/btndiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="1dp"
android:text="/"
app:layout_constraintBaseline_toBaselineOf="@+id/btn7"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:text="6"
app:layout_constraintBaseline_toBaselineOf="@+id/btn5"
app:layout_constraintEnd_toStartOf="@+id/btn5"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:text="5"
app:layout_constraintEnd_toStartOf="@+id/btn4"
app:layout_constraintStart_toEndOf="@+id/btn6"
app:layout_constraintTop_toTopOf="@+id/btn4" />
<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="4"
app:layout_constraintEnd_toStartOf="@+id/btnmul"
app:layout_constraintStart_toEndOf="@+id/btn5"
app:layout_constraintTop_toBottomOf="@+id/btn7" />

<Button
android:id="@+id/btnmul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="1dp"
android:text="*"
app:layout_constraintBaseline_toBaselineOf="@+id/btn4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn4" />

<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:text="3"
app:layout_constraintBaseline_toBaselineOf="@+id/btn2"
app:layout_constraintEnd_toStartOf="@+id/btn2"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:text="2"
app:layout_constraintBaseline_toBaselineOf="@+id/btn1"
app:layout_constraintEnd_toStartOf="@+id/btn1"
app:layout_constraintStart_toEndOf="@+id/btn3" />

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:layout_marginEnd="1dp"
android:text="1"
app:layout_constraintEnd_toStartOf="@+id/btnadd"
app:layout_constraintStart_toEndOf="@+id/btn2"
app:layout_constraintTop_toBottomOf="@+id/btn4" />
<Button
android:id="@+id/btnadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="1dp"
android:text="+"
app:layout_constraintBaseline_toBaselineOf="@+id/btn1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn1" />

<Button
android:id="@+id/btnclear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="5dp"
android:text="Clear"
app:layout_constraintBaseline_toBaselineOf="@+id/btn0"
app:layout_constraintEnd_toStartOf="@+id/btn0"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:layout_marginEnd="10dp"
android:text="0"
app:layout_constraintEnd_toStartOf="@+id/btnequ"
app:layout_constraintStart_toEndOf="@+id/btnclear"
app:layout_constraintTop_toBottomOf="@+id/btn2" />

<Button
android:id="@+id/btnequ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginEnd="1dp"
android:text="="
app:layout_constraintEnd_toStartOf="@+id/btnsub"
app:layout_constraintStart_toEndOf="@+id/btn0"
app:layout_constraintTop_toTopOf="@+id/btn0" />

<Button
android:id="@+id/btnsub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="1dp"
android:text="-"
app:layout_constraintBaseline_toBaselineOf="@+id/btnequ"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btnequ" />

<TextView
android:id="@+id/tvcontrol"
android:layout_width="362dp"
android:layout_height="33dp"
android:layout_marginTop="229dp"
android:layout_marginEnd="14dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tvresult"
android:layout_width="357dp"
android:layout_height="34dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="41dp"
app:layout_constraintBottom_toTopOf="@+id/tvcontrol"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.simplecalculator;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import javax.sql.StatementEvent;

public class MainActivity extends AppCompatActivity {

private Button one;


private Button two;
private Button three;
private Button four;
private Button five;
private Button six;
private Button seven;
private Button eight;
private Button nine;
private Button zero;
private Button add;
private Button sub;
private Button mul;
private Button div;
private Button equal;
private Button clear;
private TextView info;
private TextView result;
private final char ADDITION = '+';
private final char SUBRACTION = '-';
private final char MULTIPLICATION = '*';
private final char DIVISION = '/';
private final char EQU = 0;
private double val1 = Double.NaN;
private double val2;
private char ACTION;

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

setupUIView();

zero.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "0");
}
});

one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "1");
}
});

two.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "2");
}
});

three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "3");
}
});

four.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "4");
}
});

five.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "5");
}
});

six.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "6");
}
});

seven.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "7");
}
});

eight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "8");
}
});

nine.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info.setText(info.getText().toString() + "9");
}
});

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
compute();
ACTION = ADDITION;
result.setText(String.valueOf(val1) + "+");
info.setText(null);

}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
compute();
ACTION = SUBRACTION;
result.setText(String.valueOf(val1) + "-");
info.setText(null);

}
});

mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
compute();
ACTION = MULTIPLICATION;
result.setText(String.valueOf(val1) + "*");
info.setText(null);

}
});

div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
compute();
ACTION = DIVISION;
result.setText(String.valueOf(val1) + "/");
info.setText(null);

}
});

equal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
compute();
ACTION = EQU;
result.setText(result.getText().toString() + String.valueOf(val2) + "=" + String.valueOf(val1));
info.setText(null);
}
});

clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (info.getText().length() > 0) {
CharSequence name = info.getText().toString();
info.setText(name.subSequence(0, name.length()-1));

}
else {
val1 = Double.NaN;
val2 = Double.NaN;
info.setText(null);
result.setText(null);
}
}
});

private void setupUIView(){

one=(Button)findViewById(R.id.btn1);
zero=(Button)findViewById(R.id.btn0);
two=(Button)findViewById(R.id.btn2);
three=(Button)findViewById(R.id.btn3);
four=(Button)findViewById(R.id.btn4);
five=(Button)findViewById(R.id.btn5);
six=(Button)findViewById(R.id.btn6);
seven=(Button)findViewById(R.id.btn7);
eight=(Button)findViewById(R.id.btn8);
nine=(Button)findViewById(R.id.btn9);
sub=(Button)findViewById(R.id.btnsub);
add=(Button)findViewById(R.id.btnadd);
mul=(Button)findViewById(R.id.btnmul);
div=(Button)findViewById(R.id.btndiv);
equal=(Button)findViewById(R.id.btnequ);
clear=(Button)findViewById(R.id.btnclear);
info = (TextView)findViewById(R.id.tvcontrol);
result = (TextView)findViewById(R.id.tvresult);
}

private void compute(){


if(!Double.isNaN(val1)) {
val2 = Double.parseDouble(info.getText().toString());

switch(ACTION) {
case ADDITION:
val1 = val1 + val2;
break;
case SUBRACTION:
val1 = val1 - val2;
break;
case MULTIPLICATION:
val1 = val1 * val2;
break;
case DIVISION:
val1 = val1 / val2;
break;
case EQU:
break;
}
}
else {
val1 = Double.parseDouble(info.getText().toString());
}
}
}

HOME ADDITION
SUBRACTION MULTIPLICATION

DIVISION

MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

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

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="33dp"
android:layout_marginTop="184dp"
android:layout_marginEnd="15dp"
android:text="Enter: "
android:textSize="30sp"
app:layout_constraintEnd_toStartOf="@+id/input"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/input"
android:layout_width="0dp"
android:layout_height="51dp"
android:layout_marginEnd="13dp"
android:ems="10"
android:inputType="number"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView" />

<Button
android:id="@+id/fToc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="63dp"
android:text="F To C"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/cTof"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="60dp"
android:text="C TO F"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="@+id/fToc"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="33dp"
android:layout_marginEnd="17dp"
android:layout_marginBottom="189dp"
android:text="Result: "
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/output"
app:layout_constraintStart_toStartOf="parent" />

<EditText
android:id="@+id/output"
android:layout_width="254dp"
android:layout_height="50dp"
android:layout_marginEnd="19dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBaseline_toBaselineOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView2" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.temperatureconverter;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

private Button fToc,cTof;


private EditText input,output;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

cTof = findViewById(R.id.cTof);
fToc = findViewById(R.id.fToc);
input = findViewById(R.id.input);
output = findViewById(R.id.output);

cTof.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

double temp = Double.parseDouble(input.getText().toString());


double res = (temp * 1.0) + 32;
output.setText(String.valueOf(res));
}
});

fToc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

double temp = Double.parseDouble(input.getText().toString());


double res = (temp - 32) / 1.8;
output.setText(String.valueOf(res));
}
});

}
}
F To C Conversion C To F
Conversion

Home Page
2. Login Page

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

<EditText
android:id="@+id/etName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="167dp"
android:layout_marginBottom="27dp"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/etPassword"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/etPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginBottom="65dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/login"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etName" />

<Button
android:id="@+id/login"
android:layout_width="153dp"
android:layout_height="0dp"
android:layout_marginStart="82dp"
android:layout_marginBottom="267dp"
android:text="Login"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/etPassword"
app:layout_constraintTop_toBottomOf="@+id/etPassword" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.loginpage;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


private Button elogin;
private EditText eName;
private EditText ePassword;

private String Username = "Admin";


private String Password = "123456";

boolean isValid = false;

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

eName = findViewById(R.id.etName);
ePassword = findViewById(R.id.etPassword);
elogin = findViewById(R.id.login);

elogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String inputName = eName.getText().toString();


String inputPassword = ePassword.getText().toString();

if (inputName.isEmpty() || inputPassword.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter the details",
Toast.LENGTH_SHORT).show();
}else{

isValid = validate(inputName, inputPassword);


if(!isValid){
Toast.makeText(MainActivity.this, "Please enter the correct details",
Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();
}

}
}
});

private boolean validate(String name, String password){

if (name.equals(Username) && password.equals(Password)){


return true;
}
return false;
}

}
Home Page No details entered

Wrong details entered Login Success

MOBILE APPLICATION DEVELOPMENT


A.J.ANIRUDDH
17MIS7135

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

<EditText
android:id="@+id/etr3"
android:layout_width="64dp"
android:layout_height="42dp"
android:layout_marginStart="188dp"
android:layout_marginBottom="485dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="1.0" />

<EditText
android:id="@+id/etr1"
android:layout_width="61dp"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="200dp"
android:layout_marginBottom="299dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/etr2"
android:layout_width="61dp"
android:layout_height="40dp"
android:layout_marginStart="104dp"
android:layout_marginBottom="485dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="1.0" />

<EditText
android:id="@+id/etr4"
android:layout_width="63dp"
android:layout_height="40dp"
android:layout_marginStart="268dp"
android:layout_marginBottom="485dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="1.0" />

<EditText
android:id="@+id/etr5"
android:layout_width="52dp"
android:layout_height="0dp"
android:layout_marginStart="348dp"
android:layout_marginTop="202dp"
android:layout_marginBottom="308dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/sum"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="301dp"
android:layout_height="57dp"
android:layout_marginTop="95dp"
android:layout_marginBottom="255dp"
android:text="PLAY CARDS"
android:textSize="50sp"
app:layout_constraintBottom_toTopOf="@+id/etr9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/select"
android:layout_width="188dp"
android:layout_height="55dp"
android:layout_marginTop="314dp"
android:layout_marginEnd="3dp"
android:layout_marginBottom="50dp"
android:text="Select Cards"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/etr8"
app:layout_constraintEnd_toStartOf="@+id/sort"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />

<Button
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:text="Sort"
android:textSize="24sp"
app:layout_constraintBaseline_toBaselineOf="@+id/select"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/select" />

<EditText
android:id="@+id/etr6"
android:layout_width="60dp"
android:layout_height="50dp"
android:layout_marginStart="23dp"
android:layout_marginTop="420dp"
android:layout_marginEnd="93dp"
android:ems="10"
android:inputType="number"
app:layout_constraintEnd_toStartOf="@+id/etr8"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/etr7"
android:layout_width="69dp"
android:layout_height="48dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="251dp"
android:layout_marginBottom="270dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/etr6"
app:layout_constraintTop_toBottomOf="@+id/select"
app:layout_constraintVertical_bias="1.0" />

<EditText
android:id="@+id/etr8"
android:layout_width="61dp"
android:layout_height="58dp"
android:layout_marginEnd="174dp"
android:layout_marginBottom="269dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/etr6"
app:layout_constraintTop_toBottomOf="@+id/select" />

<EditText
android:id="@+id/etr9"
android:layout_width="63dp"
android:layout_height="52dp"
android:layout_marginStart="254dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="270dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/etr10"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/etr10"
android:layout_width="49dp"
android:layout_height="46dp"
android:layout_marginEnd="18dp"
android:layout_marginBottom="272dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/etr9"
app:layout_constraintTop_toBottomOf="@+id/etr5"
app:layout_constraintVertical_bias="1.0" />

<EditText
android:id="@+id/sum"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="128dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/etr5" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="33dp"
android:layout_marginEnd="19dp"
android:layout_marginBottom="131dp"
android:text="SUM"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sum"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etr1" />

</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA FILE:


package com.example.sort;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.stream.*;

import java.util.Arrays;
import java.util.Random;

public class MainActivity extends AppCompatActivity {


EditText et1,et2,et3,et4,et5,et6,et7,et8,et9,et10,sum;
Button b1,b2;
int ans = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Random myRandom = new Random();

et1 = findViewById(R.id.etr1);
et2 = findViewById(R.id.etr2);
et3 = findViewById(R.id.etr3);
et4 = findViewById(R.id.etr4);
et5 = findViewById(R.id.etr5);
et6 = findViewById(R.id.etr6);
et7 = findViewById(R.id.etr7);
et8 = findViewById(R.id.etr8);
et9 = findViewById(R.id.etr9);
et10 = findViewById(R.id.etr10);
sum = findViewById(R.id.sum);
b1 = findViewById(R.id.select);
b2 = findViewById(R.id.sort);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

et1.setText(String.valueOf(myRandom.nextInt(13)));
et2.setText(String.valueOf(myRandom.nextInt(13)));
et3.setText(String.valueOf(myRandom.nextInt(13)));
et4.setText(String.valueOf(myRandom.nextInt(13)));
et5.setText(String.valueOf(myRandom.nextInt(13)));

}
});

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

int[] num = new int[5];


num[0] = Integer.parseInt(et1.getText().toString());
num[1] = Integer.parseInt(et2.getText().toString());
num[2] = Integer.parseInt(et3.getText().toString());
num[3] = Integer.parseInt(et4.getText().toString());
num[4] = Integer.parseInt(et5.getText().toString());

Arrays.sort(num);
et6.setText(String.valueOf(num[0]));
et7.setText(String.valueOf(num[1]));
et8.setText(String.valueOf(num[2]));
et9.setText(String.valueOf(num[3]));
et10.setText(String.valueOf(num[4]));

int a = Integer.parseInt(et1.getText().toString());
int b = Integer.parseInt(et2.getText().toString());
int c = Integer.parseInt(et3.getText().toString());
int d = Integer.parseInt(et4.getText().toString());
int e = Integer.parseInt(et5.getText().toString());

int f = a + b + c + d + e;
sum.setText(Integer.toString(f));

}
});
}
}
HOME SELECT

SORT AND SUM


MOBILE APPLICATION DEVELOPMENT
A.J.ANIRUDDH
17MIS7135

1. Background Music Play


XML File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="157dp"
android:layout_height="154dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="116dp"
android:layout_marginEnd="46dp"
android:layout_marginRight="46dp"
android:text="MUSIC 1"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="154dp"
android:layout_height="156dp"
android:layout_marginTop="116dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="MUSIC 2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button3"
android:layout_width="162dp"
android:layout_height="173dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="46dp"
android:layout_marginRight="46dp"
android:text="MUSIC 3"
app:layout_constraintEnd_toStartOf="@+id/button4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
<Button
android:id="@+id/button4"
android:layout_width="160dp"
android:layout_height="174dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="MUSIC4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button2" />
</androidx.constraintlayout.widget.ConstraintLayout>

Main Activity Java File:


package com.example.backgroundmusic;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button b1,b2,b3,b4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button) findViewById(R.id.button3);
b4 = (Button) findViewById(R.id.button4);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isMyServiceRunning(MyService.class)) {
stopService(new Intent(MainActivity.this,
MyService.class));
} else {
startService(new Intent(MainActivity.this,
MyService.class));
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isMyServiceRunning(MyService.class)) {
stopService(new Intent(MainActivity.this,
MyService.class));
} else {
startService(new Intent(MainActivity.this,
MyService.class));
}
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isMyServiceRunning(MyService.class)) {
stopService(new Intent(MainActivity.this,
MyService.class));
} else {
startService(new Intent(MainActivity.this,
MyService.class));
}
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isMyServiceRunning(MyService.class)) {
stopService(new Intent(MainActivity.this,
MyService.class));
} else {
startService(new Intent(MainActivity.this,
MyService.class));
}
}
});
}
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager)
getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service :
manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
}

My Service File:
package com.example.backgroundmusic;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
MediaPlayer musicPlayer;

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
musicPlayer = MediaPlayer.create(this, R.raw.sample1);
musicPlayer.setLooping(false);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service started and music started.",
Toast.LENGTH_LONG).show();
musicPlayer.start();
return START_STICKY;
}

@Override
public void onDestroy() {
super.onDestroy();
musicPlayer.stop();
Toast.makeText(this, "Service stopped and music stopped",
Toast.LENGTH_LONG).show();
}
}

Android Manifest File:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.backgroundmusic">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
<service android:name=".MyService"/>
</application>

</manifest>

Music Playing Music Stopped

MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

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

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="116dp"
android:layout_marginBottom="183dp"
android:text="BROADCAST RECIEVER!!!!!"
android:textAlignment="center"
android:textSize="30dp"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.168" />

<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="62dp"
android:layout_marginEnd="62dp"
android:layout_marginBottom="339dp"
android:text="POWER CONNECTION"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

</androidx.constraintlayout.widget.ConstraintLayout>

Main Activity Java File:


package com.example.broadcastmesssages;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyReceiver myReceiver= new MyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.ACTION_POWER_DISCONNECTED");
intentFilter.addAction("android.intent.action.ACTION_POWER_CONNECTED");
registerReceiver(myReceiver,intentFilter);
}
}

MyReciever File:
package com.example.broadcastmesssages;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {

if(intent.getAction().equals("android.intent.action.ACTION_POWER_DISCONNECTED")){
Toast.makeText(context,"power is off",Toast.LENGTH_SHORT).show();
}
if (intent.getAction().equals("android.intent.action.ACTION_POWER_CONNECTED")){
Toast.makeText(context,"power is on",Toast.LENGTH_SHORT).show();

}
}

Android Manifest File:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastmesssages">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-
permission>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"></action>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"></action>
</intent-filter>
</receiver>

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

1. Animation
XML File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D8AD11"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="411dp"
android:layout_height="423dp"
android:layout_marginTop="86dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA File:


package com.example.animation;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

Animation topAnim;
ImageView image;

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

topAnim = AnimationUtils.loadAnimation(this,R.anim.top_animation);

image = findViewById(R.id.imageView);

image.setAnimation(topAnim);
}
}

TOP ANIMATION File:


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:fromXDelta="0%"
android:fromYDelta="-100%"
android:duration="2000"/>
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="1500"/>
</set>

Styles XML File: (To remove nav bar)


<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

Initial Image Final Image

MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

1. Floating Action Buttons


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

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="27dp"
android:layout_marginBottom="30dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_input_add" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="27dp"
android:layout_marginBottom="29dp"
android:clickable="true"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/fab2"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_menu_camera" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="27dp"
android:layout_marginBottom="25dp"
android:clickable="true"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/fab3"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_lock_idle_alarm" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginBottom="30dp"
android:clickable="true"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/fab2"
app:srcCompat="@android:drawable/btn_star_big_on" />
</androidx.constraintlayout.widget.ConstraintLayout>

MAIN ACTIVITY JAVA File:


package com.example.floatingbutton;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

public class MainActivity extends AppCompatActivity {

FloatingActionButton fab,fab1,fab2,fab3;
Animation fabOpen,fabClose,rotateForward,rotateBackward;
boolean isOpen = false;

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

fab = (FloatingActionButton) findViewById(R.id.fab2);


fab1 = (FloatingActionButton) findViewById(R.id.fab3);
fab2 = (FloatingActionButton) findViewById(R.id.fab4);
fab3 = (FloatingActionButton) findViewById(R.id.fab5);

fabOpen = AnimationUtils.loadAnimation(this, R.anim.fab_open);


fabClose = AnimationUtils.loadAnimation(this, R.anim.fab_close);

rotateForward = AnimationUtils.loadAnimation(this, R.anim.rotate_forward);


rotateBackward = AnimationUtils.loadAnimation(this, R.anim.rotate_backward);

fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
animateFab();
}
});

fab1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Camera is Clicked", Toast.LENGTH_SHORT).show();
}
});

fab2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Folder is Clicked", Toast.LENGTH_SHORT).show();
}
});

fab3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "star is Clicked", Toast.LENGTH_SHORT).show();
}
});

private void animateFab()


{
if (isOpen)
{
fab.startAnimation(rotateForward);
fab1.startAnimation(fabClose);
fab2.startAnimation(fabClose);
fab3.startAnimation(fabClose);
fab1.setClickable(false);
fab2.setClickable(false);
fab3.setClickable(false);
isOpen=false;
}
else
{
fab.startAnimation(rotateBackward);
fab1.startAnimation(fabOpen);
fab2.startAnimation(fabOpen);
fab3.startAnimation(fabOpen);
fab1.setClickable(true);
fab2.setClickable(true);
fab3.setClickable(true);
isOpen=true;
}
}

}
fab_open.XML File:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<scale
android:fromXScale="0.0"
android:fromYScale="0.0"
android:toXScale="0.8"
android:toYScale="0.8"
android:pivotX="50%"
android:pivotY="50%"
android:duration="300"

android:interpolator="@android:anim/linear_interpolator"/>

<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300"
android:interpolator="@android:anim/accelerate_interpolator"/>

</set>

fab_close.XML File:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<scale
android:fromXScale="0.8"
android:fromYScale="0.8"
android:toXScale="0.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="300"

android:interpolator="@android:anim/linear_interpolator"/>

<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="300"
android:interpolator="@android:anim/accelerate_interpolator"/>

</set>

Rotate_farward.XML File:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<rotate
android:fromDegrees="0"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:duration="300"
android:interpolator="@android:anim/linear_interpolator"/>
</set>

Rotate_Backward.XML File:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<rotate
android:fromDegrees="45"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="300"
android:interpolator="@android:anim/linear_interpolator"/>

</set>

Home Page Button Clicked

Toast Message

MOBILE APPLICATION DEVELOPMENT


A.J.ANIRUDDH
17MIS7135

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

<Spinner
android:id="@+id/spinner1"
android:layout_width="405dp"
android:layout_height="66dp"
android:layout_marginStart="45dp"
android:layout_marginEnd="45dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Main Activity Java File:


package com.example.spinners;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements


AdapterView.OnItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.numbers, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}

@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String text = adapterView.getItemAtPosition(i).toString();
Toast.makeText(adapterView.getContext(), text, Toast.LENGTH_SHORT).show();
}

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

}
}

Strings.xml File:
<resources>
<string name="app_name">spinners</string>

<string-array name="numbers">
<item>Android</item>
<item>Java</item>
<item>Html</item>
<item>Css</item>
<item>Php</item>
</string-array>

</resources>
Home Spinner

Toast Message

MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

1. Recycular View
XML File:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rvprogram"/>
</LinearLayout>

Single_item XML File:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="80dp"
android:layout_height="80dp"
tools:srcCompat="@tools:sample/avatars"
android:layout_margin="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="20sp"
android:id="@+id/textview1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description"
android:textSize="20sp"
android:id="@+id/textview2"/>
</LinearLayout>
</LinearLayout>

ProgramAdapter Java File:


package com.example.recycularview;

import android.content.Context;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ProgramAdapter extends RecyclerView.Adapter<ProgramAdapter.ViewHolder> {
Context context;
String[] programNameList;
String[] programDescriptionList;
int[] programImages;
public static class ViewHolder extends RecyclerView.ViewHolder{
TextView rowName;
TextView rowDescription;
ImageView rowImage;
public ViewHolder(@NonNull View itemView) {
super(itemView);
rowName = itemView.findViewById(R.id.textview1);
rowDescription=itemView.findViewById(R.id.textview2);
rowImage=itemView.findViewById(R.id.imageView);
}
}
public ProgramAdapter(Context context,String[] programNameList,String[]
programDescriptionList,int[]
programImages){
this.context = context;
this.programNameList= programNameList;
this.programDescriptionList=programDescriptionList;
this.programImages=programImages;
}
@NonNull
@Override
public ProgramAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
LayoutInflater inflater= LayoutInflater.from(context);
View view=inflater.inflate(R.layout.single_item,parent, false);
ViewHolder viewHolder=new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull ProgramAdapter.ViewHolder holder, int position) {
holder.rowName.setText(programNameList[position]);
holder.rowDescription.setText(programDescriptionList[position]);
holder.rowImage.setImageResource(programImages[position]);
}
@Override
public int getItemCount() {
return programNameList.length;
}
}

MainActivity Java File:


package com.example.recycularview;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
RecyclerView.Adapter programAdapter;
RecyclerView.LayoutManager layoutManager;
String[] programNameList =

{"cplus","c_sharp","java","javascript","kotlin","python","ruby","swift","typescript","c_sharp","visual
_studio"};
String[] programDescriptionList={"cplus Description","c_sharp Description","java
Description","javascript Description","kotiln Description","python Description","ruby
Description","swift Description","typescript Description ","c_sharp Description","visual_studio
Description"};
int[]

programImages={R.drawable.cplus,R.drawable.c_shark,R.drawable.java,R.drawable.javascript,R.dra
wable.kotlin,R.drawable.python,R.drawable.ruby,R.drawable.swift,R.drawable.typescript,R.drawable
.c_shark,R.drawable.visual_studio};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=findViewById(R.id.rvprogram);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
programAdapter=new
ProgramAdapter(this,programNameList,programDescriptionList,programImages);
recyclerView.setAdapter(programAdapter);
}
}
MOBILE APPLICATION DEVELOPMENT

A.J.ANIRUDDH
17MIS7135

1. Database
XML File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity">

<TextView
android:id="@+id/texttitle"
android:layout_width="392dp"
android:layout_height="56dp"
android:layout_alignParentTop="true"
android:layout_marginTop="49dp"
android:text="Fill the Details:"
android:textColor="#17202A"
android:textSize="24dp"
android:textStyle="bold" />

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/texttitle"
android:layout_marginTop="28dp"
android:hint="Name"
android:inputType="textPersonName"
android:textSize="24dp" />

<EditText
android:id="@+id/contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_marginTop="36dp"
android:hint="Branch"
android:inputType="text"
android:textSize="24dp" />

<EditText
android:id="@+id/dob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact"
android:layout_marginTop="28dp"
android:hint="Mobile No"
android:inputType="number"
android:textSize="24dp" />

<Button
android:id="@+id/btnInsert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dob"
android:layout_marginTop="28dp"
android:background="#FF6700"
android:text="Insert Data"
android:textSize="24dp" />

<Button
android:id="@+id/btnDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btnInsert"
android:layout_marginTop="26dp"
android:background="#00FD6B"
android:text="Delete Data"
android:textSize="24dp" />

<Button
android:id="@+id/btnView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btnDelete"
android:layout_marginTop="31dp"
android:background="#B600FF"
android:text="View Data"
android:textSize="24dp" />

</RelativeLayout>

Main Activity Java File:


package com.example.database;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText name, contact, dob;
Button insert, delete, view;
DatabaseHelper DB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
contact = findViewById(R.id.contact);
dob = findViewById(R.id.dob);
insert = findViewById(R.id.btnInsert);
delete = findViewById(R.id.btnDelete);
view = findViewById(R.id.btnView);
DB = new DatabaseHelper(this);
insert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String nameTXT = name.getText().toString();
String contactTXT = contact.getText().toString();
String dobTXT = dob.getText().toString();
Boolean checkinsertdata = DB.insertuserdata(nameTXT, dobTXT, contactTXT);
if(checkinsertdata==true)
Toast.makeText(MainActivity.this, "Data Inserted",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "Data Not Inserted",
Toast.LENGTH_SHORT).show();
} });

delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String nameTXT = name.getText().toString();
Boolean checkudeletedata = DB.deletedata(nameTXT);
if(checkudeletedata==true)
Toast.makeText(MainActivity.this, "Data Deleted",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "Data Not Deleted",
Toast.LENGTH_SHORT).show();
} });
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Cursor res = DB.getdata();
if(res.getCount()==0){
Toast.makeText(MainActivity.this, "No Data Exists", Toast.LENGTH_SHORT).show();
return;
}
StringBuffer buffer = new StringBuffer();
while(res.moveToNext()){
buffer.append("Name :"+res.getString(0)+"\n");
buffer.append("Date of Birth :"+res.getString(1)+"\n");
buffer.append("Contact :"+res.getString(2)+"\n\n");
}
AlertDialog.Builder builder = new
AlertDialog.Builder(MainActivity.this);
builder.setCancelable(true);
builder.setTitle("User Data");
builder.setMessage(buffer.toString());
builder.show();
} });
}}

DatabaseHelper Java File:


package com.example.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
super(context, "Userdata.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase DB) {
DB.execSQL("create Table Userdetails(name TEXT , dob TEXT primary key, contact TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase DB, int i, int i1) {
DB.execSQL("drop Table if exists Userdetails");
}
public Boolean insertuserdata(String name, String dob, String contact)
{
SQLiteDatabase DB = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name", name);
contentValues.put("contact", contact);
contentValues.put("dob", dob);
long result=DB.insert("Userdetails", null, contentValues);
if(result==-1){
return false;
}else{
return true;
}
}
public Boolean deletedata (String name)
{
SQLiteDatabase DB = this.getWritableDatabase();
Cursor cursor = DB.rawQuery("Select * from Userdetails where name = ?",
new String[]{name});
if (cursor.getCount() > 0) {
long result = DB.delete("Userdetails", "name=?", new String[]{name});
if (result == -1) {
return false;
} else {
return true;
}
} else {
return false;
}
}
public Cursor getdata ()
{
SQLiteDatabase DB = this.getWritableDatabase();
Cursor cursor = DB.rawQuery("Select * from Userdetails", null);
return cursor;
}
}

Home Insert
View ` Delete

After Delete

Das könnte Ihnen auch gefallen