Manual1 1
Manual1 1
A College of Engineering
Mission:
To provide career-oriented professional education to produce technically competent
engineers and managers with moral and ethical values.
To foster and promote an effective learning environment in the campus to be recognized
as place that encourages excellence and diversity in thoughts and endeavour.
To provide research and intellectual resources to address problems facing the industry
and the society while advancing the scopes of multidisciplinary applications.
Vision:
To be a center of excellence in providing quality education of global standards and be
a pioneer in spreading the knowledge and innovative ideas of Computer Science and
Engineering for catering the industrial demands and societal needs.
Mission:
To develop competent innovative professionals having effective communication skills
with proficiency in real world problem solving with leadership traits.
To impart quality and value based education to reach the expectations of all the
stakeholders through an ever evolving, effective and creative teaching-learning process.
To undertake salient research works for the establishment of center of excellence in the
field of Computer Science and Engineering and multi-disciplinary areas.
Layout:
1. Contents in “RelativeLayout”
Company Name
Image
2. Contents in “LinearLayout”
Name:
Job Title:
Phone Number:
Address:
Email id:
Note: Drag Company Name (TextView) and Image (ImageView) in RelativeLayout i.e,
layout appearing at the top.
Xmlns code:
activity_main.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:id="@+id/textView"
android:layout_width="200dp"
android:layout_height="71dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="false"
android:layout_marginLeft="31dp"
android:layout_marginTop="85dp"
android:layout_marginEnd="180dp"
android:layout_marginRight="180dp"
android:layout_marginBottom="39dp"
android:text="P.A. COLLEGE OF ENGINEERING"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 8
android:textAlignment="center"
android:textColor="#020202"
android:textSize="24sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView"
android:layout_width="148dp"
android:layout_height="113dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="29dp"
android:layout_marginRight="29dp"
android:layout_marginBottom="24dp"
app:srcCompat="@drawable/pacelogo" />
</RelativeLayout>
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/black" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="Tuba Nageen Nakhuda"
android:textAlignment="center"
android:textColor="#C68A8A"
android:textSize="16sp"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 9
android:textStyle="normal|bold" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="Asst. Prof. "
android:textColor="#BD9393"
android:textSize="16sp"
android:textStyle="normal|bold"
android:textAlignment="center"
/>
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="+9113456789"
android:textColor="#BD9393"
android:textSize="16sp"
android:textStyle="normal|bold"
android:textAlignment="center"/>
<TextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="Near Mangalore University, Kudla, Konaje Proper, Karnataka
574153"
android:textAlignment="center"
android:textColor="#BD9393"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 10
android:textSize="16sp"
android:textStyle="normal|bold" />
<TextView
android:id="@+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="[email protected]"
android:textAlignment="center"
android:textColor="#BD9393"
android:textSize="16sp"
android:textStyle="normal|bold" />
</LinearLayout>
MainActivity.java
package com.example.visitingcard;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Layout:
1. Contents in “ConstraintLayout”
Text: Simple Calculator
Text: Result
PlainText: Result
17 Buttons
XML File:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/btn_clear"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="C"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.903"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.864" />
<Button
android:id="@+id/btn_dot"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="."
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.079"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.74" />
<Button
android:id="@+id/btn_add"
android:layout_width="60dp"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 15
android:layout_height="60dp"
android:background="#9C27B0"
android:text="+"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.903"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.74" />
<Button
android:id="@+id/btn_equal"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="="
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.615"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.74" />
<Button
android:id="@+id/btn_5"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="5"
android:textColor="#502C2C"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 16
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.353"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.475" />
<Button
android:id="@+id/btn_2"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="2"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.353"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.609" />
<Button
android:id="@+id/btn_1"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="1"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.079"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 17
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.609" />
<Button
android:id="@+id/btn_sub"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="-"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.903"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.609" />
<Button
android:id="@+id/btn_3"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="3"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.615"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.609" />
<Button
android:id="@+id/btn_mul"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="*"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.903"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.475" />
<Button
android:id="@+id/btn_6"
android:layout_width="60dp"
android:layout_height="60dp"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 19
android:background="#9C27B0"
android:text="6"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.615"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.475" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple Calculator"
android:textColor="#E91E63"
android:textSize="24sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.551"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.022" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result"
android:textColor="#3F51B5"
android:textSize="20sp"
android:textStyle="bold"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 20
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.186"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.116" />
<Button
android:id="@+id/btn_7"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="7"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.08"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.333" />
<Button
android:id="@+id/btn_8"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="8"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.353"
app:layout_constraintStart_toStartOf="parent"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 21
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.333" />
<Button
android:id="@+id/btn_9"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="9"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.615"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.333" />
<Button
android:id="@+id/btn_div"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="#9C27B0"
android:text="/"
android:textColor="#502C2C"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.903"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.333" />
<EditText
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 22
android:id="@+id/TextInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="100dp"
android:layout_marginRight="100dp"
android:layout_marginBottom="548dp"
android:ems="10"
android:inputType="text"
android:text="Input"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
Java File:
MainActivity.java
package com.example.simplecalculator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tres=(EditText)findViewById(R.id.TextInput);
tres.setText("");
}
@Override
public void onClick(View v) {
if(v.equals(btn_0))
tres.append("0");
if(v.equals(btn_1))
tres.append("1");
if(v.equals(btn_2))
tres.append("2");
if(v.equals(btn_3))
tres.append("3");
if(v.equals(btn_4))
tres.append("4");
if(v.equals(btn_5))
tres.append("5");
if(v.equals(btn_6))
tres.append("6");
if(v.equals(btn_7))
tres.append("7");
if(v.equals(btn_8))
tres.append("8");
if(v.equals(btn_9))
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 25
tres.append("9");
if(v.equals(btn_dot))
tres.append(".");
if(v.equals(btn_add))
tres.append("+");
if(v.equals(btn_sub))
tres.append("-");
if(v.equals(btn_mul))
tres.append("*");
if(v.equals(btn_div))
tres.append("/");
if(v.equals(btn_clear))
tres.setText("");
if(v.equals(btn_equal)) {
try {
String data = tres.getText().toString();
if (data.contains("/")) {
String[] operands = data.split("/");
if(operands.length==2){
double op1 = Double.parseDouble(operands[0]);
double op2 = Double.parseDouble(operands[1]);
double result = op1/op2;
tres.setText(String.valueOf(result));
}
}
if (data.contains("*")) {
String[] operands = data.split("\\*");
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 26
if(operands.length==2){
double op1 = Double.parseDouble(operands[0]);
double op2 = Double.parseDouble(operands[1]);
double result = op1*op2;
tres.setText(String.valueOf(result));
}
}
if (data.contains("+")) {
String[] operands = data.split("\\+");
if(operands.length==2){
double op1 = Double.parseDouble(operands[0]);
double op2 = Double.parseDouble(operands[1]);
Layout:
1. Two layouts: Sign Up Activity and Sign In Activity
2. Sign Up Activity
Constraint Layout
Two TextView: Username and Password (OR) write it in the hint of
Plaintext and Password
One Plaintext: Username
One Password: Password
One Button: Sign Up
3. Sign In Activity
Constraint Layout
Two Textview: Username and Password (OR) write it in the hint of Plaintext
and Password
Xml Code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:hint="Password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Up"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 31
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.717" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Up Page"
android:textColor="@color/black"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.11" />
</android.support.constraint.ConstraintLayout>
activity_sign_in.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".sign_in">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 32
android:text="Sign In Page"
android:textColor="@color/black"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.143" />
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="UserName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.38" />
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:hint="Password"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 33
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.581" />
<Button
android:id="@+id/signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign In"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.8" />
</android.support.constraint.ConstraintLayout>
Java Code:
MainActivity.java
package com.example.signup;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String regularExpr="^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-z\\d@$!]{8,}$";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = findViewById(R.id.username);
password = findViewById(R.id.password);
signUpBtn = findViewById(R.id.signup);
signUpBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String uname = username.getText().toString();
String pwd = password.getText().toString();
if(validatePassword(pwd)){
bundle.putString("username",uname);
bundle.putString("password",pwd);
intent.putExtras(bundle);
startActivity(intent);
}
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 35
else{
Toast.makeText(MainActivity.this, "Invaild Password",
Toast.LENGTH_SHORT).show();
}
}
});
}
public boolean validatePassword(String pwd){
Pattern pattern = Pattern.compile(regularExpr);
Matcher matcher = pattern.matcher(pwd);
return matcher.matches();
}
}
sign_in.java
package com.example.signup;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
EditText username,password;
Button signInBtn;
int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 36
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
username = findViewById(R.id.username);
password = findViewById(R.id.password);
signInBtn = findViewById(R.id.signin);
signInBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = username.getText().toString();
String pass = password.getText().toString();
Layout:
1. Contents in “ConstraintLayout”
Text: Changing Wallpaper Application
Button: Click Here To Change Wallpaper
Steps to Create Wallpaper Changing Application:
1. Create a New Android Project with Empty Activity.
2. Open activity_main.xml file from res layout folder, check/add LinearLayout as the
root view.
3. Create the layout
4. Add Button component & change the following properties:
Size: 38dp
Text: Click Here to Change Wall Paper
5. Add 3 or More images to drawable folder (res->drawable)
6. Declare uses permission android.permission.SET_WALLPAPPER in the
AndroidManifest.xml file
7. Schedule Timer task to change the wallpaper on every 30 seconds interval.
8. Initialize and use WallpaperManager.setBitmap() method to change the wallpaper.
Xml Code:
activity_main.xml
<?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"
android:gravity="center"
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFEB3B"
android:text="CHANGE WALLPAPER" />
</LinearLayout>
Java Code:
MainActivity.java
package com.example.wallpaper;
import android.app.WallpaperManager;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
Button btn;
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WallpaperManager wallpapermanager =
WallpaperManager.getInstance(getBaseContext());
try {
wallpapermanager.setBitmap(BitmapFactory.decodeResource(getResources(),
images[i]));
i++;
if (i == 4) {
i = 0;
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 41
class ChangeWallpaper extends TimerTask {
@Override
public void run() {
WallpaperManager wallpapermanager =
WallpaperManager.getInstance(getBaseContext());
try {
wallpapermanager.setBitmap(BitmapFactory.decodeResource(getResources(),
images[i]));
i++;
if (i == 4) {
i = 0;
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
Manifest Code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wallpaper">
<uses-permission android:name="android.permission.SET_WALLPAPER">
</uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 42
android:supportsRtl="true"
android:theme="@style/Theme.Wallpaper">
<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>
Output:
Layout:
1. Contents in “ConstraintLayout”
TextView: Counter Application
PlainText: Counter Value
2 Buttons: Start and Stop
Steps to Create Counter Application:
1. Create a New Android Project with Empty Activity.
2. Open activity_main.xml file from res layout folder, check/add ConstraintLayout as
the root view.
3. Create the layout design using Drag and Drop framework.
4. Add Listeners to Button Click Event:
Create a class which implements OnClickListener interface.
Override onClick() method of OnClickListener Interface.
Register the button for click event by calling setOnClickListener() method of
View class and pass the object of the class that implemented OnClickListener
Interface.
5. Create a Thread to start the counter logic.
6. Steps to Create a Thread
Create a class that extends Thread Class.
Override run method of Thread Class.
Use start() method of thread class to start the thread.
Xml Code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/countervalue1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COUNTER APPLICATION"
android:textColor="#E91E63"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.533"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.109" />
<Button
android:id="@+id/stopbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#9C27B0"
android:text="STOP"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.723" />
<TextView
android:id="@+id/countervalue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Counter Value"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 46
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.227" />
</android.support.constraint.ConstraintLayout>
Java Code:
MainActivity.java
package com.example.counter;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
countervalue = findViewById(R.id.countervalue);
startbtn = findViewById(R.id.startbtn);
startbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
count = 0;
running = true;
startThread();
}
});
stopbtn = findViewById(R.id.stopbtn);
stopbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
running = false;
}
});
}
class NewThread extends Thread{
@Override
public void run(){
while(running)
{
count++;
mainHandler.post(new Runnable() {
@Override
public void run() {
countervalue.setText(String.valueOf(count));
}
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 48
});
Log.d(TAG, "startThread" +i);
try{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}
Output:
Layout:
1. Contents in “ConstraintLayout”
TextView: Counter Application
PlainText: Counter Value
2 Buttons: Start and Stop
Steps to Create XML and JSON Data Parser Application:
1. Create a New Android Project with Empty Activity.
2. Open activity_main.xml file from res-> layout folder, check/add ConstraintLayout
as the root view.
3. Create the layout design using Drag and Drop framework.
4. Add Listeners to Button Click Event:
Create a class which implements OnClickListener interface.
Override onClick() method of OnClickListener Interface.
Register the button for click event by calling setOnClickListener() method
of View class and pass the object of the class that implemented
OnClickListener Interface.
5. Create viewActivity
File -> New - > Activity - > Empty Activity - > Empty View Activity
6. Design activity_view.xml and code viewActivity.java
7. Create assets folder
Xml Code:
activity_main.xml
<Button
android:id="@+id/xmlbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="226dp"
android:background="#9C27B0"
android:text="Parse XML"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/jsonbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="59dp"
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Parse Your Data"
android:textColor="#E91E63"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.148" />
</android.support.constraint.ConstraintLayout>
activity_view.xml
<TextView
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 52
android:id="@+id/jsonPlaceHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#2196F3"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.482"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.555" />
<TextView
android:id="@+id/xmlPlaceHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#FFEB3B"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.482"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.394" />
<TextView
android:id="@+id/xmlHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XML Data"
android:textColor="#F44336"
android:textStyle="bold"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 53
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.213" />
<TextView
android:id="@+id/jsonHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="JSON Data"
android:textColor="#F44336"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.488"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.268" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Parse Data"
android:textColor="#009688"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 54
app:layout_constraintVertical_bias="0.066" />
</android.support.constraint.ConstraintLayout>
Java Code:
MainActivity.java
package com.example.dataparser1;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xmlbtn = findViewById(R.id.xmlbtn);
jsonbtn = findViewById(R.id.jsonbtn);
xmlbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,viewActivity.class);
intent.putExtra("mode",1);
startActivity(intent);
}
jsonbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,viewActivity.class);
intent.putExtra("mode",2);
startActivity(intent);
}
});
}
}
viewActivity.java
package com.example.dataparser1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 56
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
int mode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
mode = getIntent().getIntExtra("mode",0);
xmlPlaceHolder = findViewById(R.id.xmlPlaceHolder);
jsonPlaceholder = findViewById(R.id.jsonPlaceHolder);
xmlHeading = findViewById(R.id.xmlHeading);
jsonHeading = findViewById(R.id.jsonHeading);
if(mode==1)
{
parseXML();
}
if(mode==2)
{
parseJSON();
}
}
//String(array)
try{
InputStream inputStream = getAssets().open("input.json");
//2nd step
inputStream.read(buffer);
//3rd step
Log.e("data","parseJSON"+jsonObject);
Log.e("data", "parseJSON:"+jsonObject.getClass().getName());
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 58
JSONObject cityObject = jsonObject.getJSONObject("City"); //for single city value
Log.e("data","parseJSON:"+cityName);
jsonPlaceholder.setText("City-Name - "+cityName+"\n");
jsonPlaceholder.append("Longitude - "+longitude+"\n");
jsonPlaceholder.append("Latitude - "+latitude+"\n");
jsonPlaceholder.append("Temperature - "+temperature+"\n");
jsonPlaceholder.append("Humidity - "+humidity+"\n");
}
catch (IOException e)
{
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
jsonPlaceholder.setText("");
jsonHeading.setText("");
try{
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 59
InputStream inputStream = getAssets().open("input.xml");
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder =
documentBuilderFactory.newDocumentBuilder();
for(int i=0;i<cityList.getLength();i++)
{
Node c = cityList.item(i);
if(c.getNodeType() == Node.ELEMENT_NODE)
{
Element city = (Element) c;
for(int j=0;j<cityDetailList.getLength();j++)
{
Node n = cityDetailList.item(j);
if(n.getNodeType() == Node.ELEMENT_NODE)
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 60
{
Element cityDetail = (Element) n;
xmlPlaceHolder.append(tagValue+" - "+value);
xmlPlaceHolder.append("\n");
}
}
}
}
}
catch (IOException e)
{
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
}
}
input.xml
<?xml version="1.0"?>
<Records>
<City>
<City-Name>Mangalore</City-Name>
<Longitude>78</Longitude>
<Latitude>13</Latitude>
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 61
<Temperature>30</Temperature>
<Humidity>90%</Humidity>
</City>
</Records>
input.json
"City":
{
"City-Name": "Bengaluru",
"Longitude": "78,",
"Latitude": "13",
"Temperature": "30",
"Humidity": "90%"
}
}
Layout:
1. Contents in “ConstraintLayout”
TextView: Text To Speech Application
PlainText: Type
Button: Convert Text to Speech
Steps to Create Text To Speech Application:
1. Create a New Android Project with Empty Activity.
2. Open activity_main.xml file from res layout folder, check/add ConstraintLayout as
the root view.
3. Create the layout design using Drag and Drop framework.
4. Add Listeners to Button Click Event:
Create a class which implments OnClickListener interface.
Override onClick() method of OnClickListener Interface.
Register the button for click event by calling setOnClickListener() method of
View class and pass the object of the class that implemented OnClickListener
Interface.
5. Initialize TextToSpeech Engine and the Language to Speak using setLanguage()
method
6. Use Speak() method to speak the text passed to it.
Xml Code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text To Speech Application"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.15" />
<EditText
android:id="@+id/EnterValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="128dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Your Text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/btnspeak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 65
android:layout_marginTop="92dp"
android:background="#FFEB3B"
android:text="Convert The Text To Speech"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/EnterValue" />
</android.support.constraint.ConstraintLayout>
Java Code:
MainActivity.java
package com.example.texttospeech;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;
EditText EnterValue;
Button btnspeak;
TextToSpeech textToSpeech;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
btnspeak = findViewById(R.id.btnspeak);
EnterValue = findViewById(R.id.EnterValue);
if(status == TextToSpeech.SUCCESS) {
textToSpeech.setLanguage(Locale.ENGLISH);
}
else
{
Log.e("Failed", "onInit : Failed");
}
}
});
btnspeak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = EnterValue.getText().toString();
Toast.makeText(getBaseContext(),text,Toast.LENGTH_LONG).show();
textToSpeech.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
});
}
}
Layout:
1. Contents in “ConstraintLayout”
TextView: Call and Save Application
PlainText: To display the numbers
15 Buttons: 0-9, Delete, Call and Save
Steps to Create Call and Save Application:
1. Create a New Android Project with Empty Activity.
2. Open activity_main.xml file from res layout folder, check/add ConstraintLayout as
the
3. root view.
4. Create the layout design using Drag and Drop framework.
5. Add Listeners to Button Click Event:
6. Create a class which implments OnClickListener interface.
7. Override onClick() method of OnClickListener Interface.
8. Register the button for click event by calling setOnClickListener() method of View
class and pass the object of the class that implemented OnClickListener Interface.
9. Declare uses permission android.permission.CALL_PHONE in the manifest file.
10. Use ACTION_CALL intent name and pass the “tel:<phone-number> as URI in intent
data and start the call activity.
11. Use intent name and pass the “Telephone Number” and “unknown” as name as intent
data call Contacts Save Activity
<Button
android:id="@+id/btnCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="Call"
app:layout_constraintEnd_toStartOf="@+id/btn3"
app:layout_constraintHorizontal_bias="0.506"
app:layout_constraintStart_toEndOf="@+id/btn1"
app:layout_constraintTop_toBottomOf="@+id/btn0" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="Save"
app:layout_constraintEnd_toStartOf="@+id/btn2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnstar" />
<Button
android:id="@+id/btn0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="0"
app:layout_constraintEnd_toStartOf="@+id/btn3"
app:layout_constraintHorizontal_bias="0.506"
app:layout_constraintStart_toEndOf="@+id/btn1"
app:layout_constraintTop_toBottomOf="@+id/btn8" />
<Button
android:id="@+id/btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.493"
app:layout_constraintStart_toEndOf="@+id/btn2"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 71
app:layout_constraintTop_toBottomOf="@+id/btn6" />
<Button
android:id="@+id/btnstar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="*"
app:layout_constraintEnd_toStartOf="@+id/btn2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn7" />
<Button
android:id="@+id/btnHash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="#"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.493"
app:layout_constraintStart_toEndOf="@+id/btn2"
app:layout_constraintTop_toBottomOf="@+id/btn9" />
<Button
android:id="@+id/btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="8"
app:layout_constraintEnd_toStartOf="@+id/btn3"
app:layout_constraintHorizontal_bias="0.506"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 72
app:layout_constraintStart_toEndOf="@+id/btn1"
app:layout_constraintTop_toBottomOf="@+id/btn5" />
<Button
android:id="@+id/btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:background="#9C27B0"
android:text="7"
app:layout_constraintEnd_toStartOf="@+id/btn2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn4" />
<Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:background="#9C27B0"
android:text="4"
app:layout_constraintEnd_toStartOf="@+id/btn2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn1" />
<Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:background="#9C27B0"
android:text="6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.493"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 73
app:layout_constraintStart_toEndOf="@+id/btn2"
app:layout_constraintTop_toBottomOf="@+id/btn3" />
<Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:background="#9C27B0"
android:text="5"
app:layout_constraintEnd_toStartOf="@+id/btn3"
app:layout_constraintHorizontal_bias="0.506"
app:layout_constraintStart_toEndOf="@+id/btn1"
app:layout_constraintTop_toBottomOf="@+id/btn2" />
<EditText
android:id="@+id/display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.577"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.153" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:background="#9C27B0"
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 74
android:text="1"
app:layout_constraintEnd_toStartOf="@+id/btn2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/display" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:background="#9C27B0"
android:text="2"
app:layout_constraintEnd_toStartOf="@+id/btn3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn1"
app:layout_constraintTop_toBottomOf="@+id/display" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:background="#9C27B0"
android:text="3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn2"
app:layout_constraintTop_toBottomOf="@+id/display" />
</android.support.constraint.ConstraintLayout>
Java Code:
MainActivity.java
import android.content.Intent;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn0 = findViewById(R.id.btn0);
btn1 = findViewById(R.id.btn1);
btn2 = findViewById(R.id.btn2);
btn3 = findViewById(R.id.btn3);
btn4 = findViewById(R.id.btn4);
btn5 = findViewById(R.id.btn5);
btn6 = findViewById(R.id.btn6);
btn7 = findViewById(R.id.btn7);
btn8 = findViewById(R.id.btn8);
btn9 = findViewById(R.id.btn9);
btnCall = findViewById(R.id.btnCall);
btnStar = findViewById(R.id.btnstar);
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 76
btnHash = findViewById(R.id.btnHash);
btnRemove = findViewById(R.id.btnRemove);
btnSave = findViewById(R.id.btnSave);
display = findViewById(R.id.display);
btn0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("0");
}
});
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("1");
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("2");
}
});
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("3");
}
});
btn5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("5");
}
});
btn6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("6");
}
});
btn7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("7");
}
});
btn8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("8");
}
});
Prof. Tuba Nageen Nakhuda Dept. of CSE, PACE, Mangaluru 78
btn9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("9");
}
});
btnStar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("*");
}
});
btnHash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
display.append("#");
}
});
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = display.getText().toString();
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME,"Unknown");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, data);
startActivity(intent);
}
});
btnCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = display.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+data));
startActivity(intent);
}
});
}
}