0% found this document useful (0 votes)
79 views30 pages

Mobile Application Development Output

This document describes the code for developing two mobile applications. The first application displays text and images on the screen. The second application creates a basic calculator app with buttons for numbers and operators, and displays calculation results in an edit text field. The code includes Java classes, XML layout files, and defines button click listeners and logic for performing calculations.

Uploaded by

Karthik Bhargav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views30 pages

Mobile Application Development Output

This document describes the code for developing two mobile applications. The first application displays text and images on the screen. The second application creates a basic calculator app with buttons for numbers and operators, and displays calculation results in an edit text field. The code includes Java classes, XML layout files, and defines button click listeners and logic for performing calculations.

Uploaded by

Karthik Bhargav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Mobile Application development

1.
MainActivity.java
package com.example.program1;

import android.support.v7.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);
}
}

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:orientation="vertical"
android:layout_gravity="center"
tools:context=".program1"
>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FERRARI"
android:textSize="20dp"
android:paddingTop="10dp"
android:textColor="#456787"
android:id="@+id/lbl_company_name"
android:layout_marginRight="10dp"
/>

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ferri"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/lbl_company_name"
/>
</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Job Title"
android:textSize="20dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone Number"
android:textSize="20dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="20dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email, website, fax details"
android:layout_gravity="center"
android:textSize="20dp"
/>
First Program Output
2.
package com.example.program2;

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.Pattern;

public class Calci extends AppCompatActivity implements View.OnClickListener {


Button btnZero, btnOne, btnTwo, btnThree, btnFour, btnFive, btnSix, btnSeven,
btnEight, btnNine;
Button btnAdd, btnSub, btnMul, btnDiv, btnDot, btnClear, btnEqual;

EditText etResult;

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

etResult = (EditText)findViewById(R.id.etResult);
etResult.setText("");

btnZero = (Button)findViewById(R.id.btnZero);
btnZero.setOnClickListener(this);

btnOne = (Button)findViewById(R.id.btnOne);
btnOne.setOnClickListener(this);

btnTwo = (Button)findViewById(R.id.btnTwo);
btnTwo.setOnClickListener(this);

btnThree = (Button)findViewById(R.id.btnThree);
btnThree.setOnClickListener(this);

btnFour = (Button)findViewById(R.id.btnFour);
btnFour.setOnClickListener(this);

btnFive = (Button)findViewById(R.id.btnFive);
btnFive.setOnClickListener(this);

btnSix = (Button)findViewById(R.id.btnSix);
btnSix.setOnClickListener(this);

btnSeven = (Button)findViewById(R.id.btnSeven);
btnSeven.setOnClickListener(this);

btnEight = (Button)findViewById(R.id.btnEight);
btnEight.setOnClickListener(this);

btnNine = (Button)findViewById(R.id.btnNine);
btnNine.setOnClickListener(this);

btnAdd = (Button)findViewById(R.id.btnAdd);
btnAdd.setOnClickListener(this);

btnSub = (Button)findViewById(R.id.btnSub);
btnSub.setOnClickListener(this);

btnMul = (Button)findViewById(R.id.btnMul);
btnMul.setOnClickListener(this);

btnDiv = (Button)findViewById(R.id.btnDiv);
btnDiv.setOnClickListener(this);

btnDot = (Button)findViewById(R.id.btnDot);
btnDot.setOnClickListener(this);

btnEqual = (Button)findViewById(R.id.btnEqual);
btnEqual.setOnClickListener(this);

btnClear = (Button)findViewById(R.id.btnClear);
btnClear.setOnClickListener(this);
}
public void onClick(View v)
{
//take actions for buttons 0-9
if(v.equals(btnZero)) {
etResult.append("0");
}

if(v.equals(btnOne)) {
etResult.append("1");
}

if(v.equals(btnTwo)) {
etResult.append("2");
}

if(v.equals(btnThree))
etResult.append("3");

if(v.equals(btnFour))
etResult.append("4");

if(v.equals(btnFive))
etResult.append("5");

if(v.equals(btnSix))
etResult.append("6");

if(v.equals(btnSeven))
etResult.append("7");

if(v.equals(btnEight))
etResult.append("8");

if(v.equals(btnNine))
etResult.append("9");

if(v.equals(btnAdd))
etResult.append("+");
if(v.equals(btnSub))
etResult.append("-");

if(v.equals(btnMul))
etResult.append("*");

if(v.equals(btnDiv))
etResult.append("/");

if(v.equals(btnDot))
etResult.append(".");

//CLEAR THE DISPLAY WHEN CLEAR BUTTON IS PRESSED


if(v.equals(btnClear))
etResult.setText("");

//handle equals
if(v.equals(btnEqual))
{
try{
String data = etResult.getText().toString();

//handle division
if(data.contains("/"))
{
String[] operands = data.split("/");
if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 / operand2;
etResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"Invalid
input",Toast.LENGTH_LONG).show();
}
}
if(data.contains("*"))
{
String[] operands = data.split(Pattern.quote("*"));
if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 * operand2;
etResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"Invalid
input",Toast.LENGTH_LONG).show();
}
}
if(data.contains("-"))
{
String[] operands = data.split("-");
if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 - operand2;
etResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"Invalid
input",Toast.LENGTH_LONG).show();
}
}
if(data.contains("+"))
{
String[] operands = data.split("+");
if(operands.length==2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 + operand2;
etResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"Invalid
input",Toast.LENGTH_LONG).show();
}
}

}
catch (Exception e)
{
Toast.makeText(getBaseContext(),"Invalid
input",Toast.LENGTH_LONG).show();
}
}

}
}
activity_calci.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=".Calci"
android:background="@drawable/dark">

<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="88dp"
android:layout_marginTop="51dp"
android:layout_marginBottom="640dp"
android:text="Simple Calculator"
android:textColor="#090909"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="53dp"
android:text="Result"
android:textColor="#090909"
android:textSize="22dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

<Button
android:id="@+id/btnOne"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnFour" />

<Button
android:id="@+id/btnTwo"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="2"
app:layout_constraintStart_toEndOf="@+id/btnOne"
app:layout_constraintTop_toBottomOf="@+id/btnFive" />

<Button
android:id="@+id/btnThree"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="3"
app:layout_constraintStart_toEndOf="@+id/btnTwo"
app:layout_constraintTop_toBottomOf="@+id/btnSix" />

<Button
android:id="@+id/btnSub"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="-"
app:layout_constraintStart_toEndOf="@+id/btnThree"
app:layout_constraintTop_toBottomOf="@+id/btnMul" />

<Button
android:id="@+id/btnFour"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnSeven" />

<Button
android:id="@+id/btnFive"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="5"
app:layout_constraintStart_toEndOf="@+id/btnFour"
app:layout_constraintTop_toBottomOf="@+id/btnEight" />

<Button
android:id="@+id/btnSix"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="6"
app:layout_constraintStart_toEndOf="@+id/btnFive"
app:layout_constraintTop_toBottomOf="@+id/btnNine" />

<Button
android:id="@+id/btnMul"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="*"
app:layout_constraintStart_toEndOf="@+id/btnSix"
app:layout_constraintTop_toBottomOf="@+id/btnDiv" />
<Button
android:id="@+id/btnSeven"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="235dp"
android:layout_marginEnd="45dp"
android:text="7"
app:layout_constraintEnd_toStartOf="@+id/btnEight"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

<Button
android:id="@+id/btnEight"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="235dp"
android:text="8"
app:layout_constraintStart_toEndOf="@+id/btnSeven"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

<Button
android:id="@+id/btnNine"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="235dp"
android:text="9"
app:layout_constraintStart_toEndOf="@+id/btnEight"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

<Button
android:id="@+id/btnDiv"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="235dp"
android:text="/"
app:layout_constraintStart_toEndOf="@+id/btnNine"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

<Button
android:id="@+id/btnDot"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="."
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnOne" />

<Button
android:id="@+id/btnZero"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="0"
app:layout_constraintStart_toEndOf="@+id/btnDot"
app:layout_constraintTop_toBottomOf="@+id/btnTwo" />

<Button
android:id="@+id/btnEqual"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="="
app:layout_constraintStart_toEndOf="@+id/btnZero"
app:layout_constraintTop_toBottomOf="@+id/btnThree" />

<Button
android:id="@+id/btnAdd"
android:layout_width="65dp"
android:layout_height="41dp"
android:layout_marginStart="25dp"
android:layout_marginTop="30dp"
android:text="+"
app:layout_constraintStart_toEndOf="@+id/btnEqual"
app:layout_constraintTop_toBottomOf="@+id/btnSub" />

<Button
android:id="@+id/btnClear"
android:layout_width="73dp"
android:layout_height="41dp"
android:layout_marginStart="168dp"
android:layout_marginTop="28dp"
android:text="C"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnAdd" />

<EditText
android:id="@+id/etResult"
android:layout_width="276dp"
android:layout_height="60dp"
android:layout_marginStart="25dp"
android:layout_marginTop="120dp"
android:layout_marginEnd="40dp"
android:ems="10"
android:inputType="number|text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.279"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

</android.support.constraint.ConstraintLayout>
SECOND PROGRAM OUTPUT
3.

MainActivity.java
package com.example.program2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import android.view.View;

import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {
EditText etUsername;
EditText etPassword;
Button btnSignup;

String regularExpression = "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-


z\\d@$!]{8,}$";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername=(EditText)findViewById(R.id.etUsername);
etPassword=(EditText)findViewById(R.id.etPassword);
btnSignup=(Button)findViewById(R.id.btnSignup);
btnSignup.setOnClickListener(this);

}
public void onClick(View v)
{
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
if(validatePassword(password))
{
Bundle bundle = new Bundle();
bundle.putString("user",username);
bundle.putString("Lab@2018",password);
Intent it = new Intent( this,LoginActivity.class);
it.putExtra("data",bundle);

startActivity(it);
}
else
{
Toast.makeText(getBaseContext(),"Invalid
password",Toast.LENGTH_LONG).show();
}

}
public boolean validatePassword(String password)
{
Pattern pattern = Pattern.compile(regularExpression);
Matcher matcher = pattern.matcher(password);
return matcher.matches();
}
}

LoginActivity.java
package com.example.program2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View;

public class LoginActivity extends AppCompatActivity implements


View.OnClickListener{
EditText etUsername;
EditText etPassword;
Button btnLogin;

String user,pass;
int count = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etUsername=(EditText)findViewById(R.id.etUsername);
etPassword=(EditText)findViewById(R.id.etPassword);
btnLogin=(Button)findViewById(R.id.btnLogin);

btnLogin.setOnClickListener(this);
Bundle bundle= getIntent().getBundleExtra("data");
user = bundle.getString("user");
pass = bundle.getString("Lab@2018");
}
public void onClick(View v)
{
String user1 = etUsername.getText().toString();
String pass1 = etPassword.getText().toString();

if(user.equals(user1) && pass.equals(pass1))


{
Toast.makeText(this,"Login Successful",Toast.LENGTH_LONG).show();

}
else
{
count++;
if(count==3)
{
btnLogin.setEnabled(false);
Toast.makeText(this,"Failed Login
Attempts",Toast.LENGTH_LONG).show();

}
else
{
Toast.makeText(this,"Login
Failed"+count,Toast.LENGTH_LONG).show();
}
}
}
}

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"
android:background="@drawable/dark"
android:scrollbarThumbHorizontal="@color/cardview_light_background"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Sign Up Form"
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginTop="60dp"
android:text="Username"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />

<EditText
android:id="@+id/etUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="88dp"
android:text="Password"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5" />

<EditText
android:id="@+id/etPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_marginEnd="20dp"
android:ems="10"
android:inputType="textPassword"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etUsername" />

<Button
android:id="@+id/btnSignup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="SIGN UP"
android:textSize="20dp"
android:onClick="onClick"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etPassword" />
</android.support.constraint.ConstraintLayout>

Activity_login.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=".LoginActivity"
android:background="@drawable/light">

<TextView
android:id="@+id/textView"
android:layout_width="160dp"
android:layout_height="34dp"
android:layout_marginTop="36dp"
android:text="Login Form"
android:textColor="#F8F6F6"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="76dp"
android:text="Username"
android:textColor="#F8F6F6"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/etUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_marginEnd="20dp"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#F1EBEB"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="88dp"
android:text="Password"
android:textColor="#F8F6F6"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

<EditText
android:id="@+id/etPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:layout_marginEnd="20dp"
android:ems="10"
android:inputType="textPassword"
android:textColor="#F1EBEB"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etUsername" />

<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="LOGIN "
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etPassword" />
</android.support.constraint.ConstraintLayout>

THIRD PROGRAM OUTPUT


4. MainActivity.java
package com.example.program4;

import android.app.WallpaperManager;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener{
Button btnWallpaper;

boolean running;
int[] imagesArray = new int[]{
R.drawable.angry,
R.drawable.cutie,
R.drawable.cat,
R.drawable.pikachu,
R.drawable.rabbit,
R.drawable.micky
};

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

btnWallpaper=(Button)findViewById(R.id.btnWallpaper);
btnWallpaper.setOnClickListener(this);
}
public void onClick(View view){
Log.i("Wallpaper","onClick...");
System.out.println("Wallpaper -> onClick...");

if(!running)
{
new Timer().schedule(new MyTimer(),0,10000);
running=true;

}
}
class MyTimer extends TimerTask
{
public void run()
{
Log.i("WallPaper th:","here..."+i);
try{
WallpaperManager wallpaperManager =
WallpaperManager.getInstance(getBaseContext());

wallpaperManager.setBitmap(BitmapFactory.decodeResource(getResources(),imagesArray
[i]));
i++;
if(i==6) i=0;
}
catch (Exception e)
{
Log.i("Wall Paper th",e.toString());
}
}
}

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/btnWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="100dp"
android:layout_marginEnd="20dp"
android:text="Click here to change the wallpaper"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />;
tools:layout_editor_absoluteX="166dp"
tools:layout_editor_absoluteY="221dp" />
</android.support.constraint.ConstraintLayout>
FOURTH PROGRAM OUTPUT
5.

MainActivity.java
package com.example.program5;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener{
Button btnStart, btnStop;
TextView tvCounter;

int counter = 0;
boolean running = false;

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

btnStart = (Button)findViewById(R.id.btn_sw_start);
btnStop = (Button)findViewById(R.id.btn_sw_stop);
tvCounter = (TextView)findViewById(R.id.tv_stop_watch);

btnStart.setOnClickListener(this);
btnStop.setOnClickListener(this);

class MyCounter extends Thread{


@Override
public void run()
{
while ( running )
{
counter++;
handler.sendEmptyMessage(counter);

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

Handler handler = new Handler(){


public void handleMessage(Message m)
{
tvCounter.setText(String.valueOf(m.what));
}
};

@Override
public void onClick(View view) {
if ( view.equals(btnStart ))
{
counter = 0;
running = true;
new MyCounter().start();
}
else if ( view.equals(btnStop))
{
running = false;
}
}
}

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/tv_stop_watch"
android:layout_width="169dp"
android:layout_height="70dp"
android:layout_marginTop="50dp"
android:text=""
android:textSize = "20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn_sw_start"
android:layout_width="184dp"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:text="Start"
android:textSize = "20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_stop_watch" />

<Button
android:id="@+id/btn_sw_stop"
android:layout_width="168dp"
android:layout_height="85dp"
android:layout_marginTop="52dp"
android:text="Stop"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_sw_start" />
</android.support.constraint.ConstraintLayout>

FIFTH PROGRAM OUTPUT


7. Develop a simple application with one Edit Text so that the user can write some text in it. Create
a button called “Convert Text to Speech” that converts the user input text into voice.

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/textView6"
android:layout_width="202dp"
android:layout_height="63dp"
android:layout_marginTop="40dp"
android:text="Enter the Text"
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/et_input_text"
android:layout_width="319dp"
android:layout_height="95dp"
android:layout_marginTop="80dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />

<Button
android:id="@+id/btn_text_to_speech"
android:layout_width="202dp"
android:layout_height="66dp"
android:layout_marginTop="80dp"
android:text="Convert to Speech"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_input_text" />

</android.support.constraint.ConstraintLayout>
Main Activity.java
package com.example.program_7a;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Locale;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener{

EditText etInputText;
Button btnSpeak;
TextToSpeech textToSpeech;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etInputText = (EditText)findViewById(R.id.et_input_text);
btnSpeak = (Button)findViewById(R.id.btn_text_to_speech);

btnSpeak.setOnClickListener(this);

textToSpeech=new TextToSpeech(getBaseContext(),
new TextToSpeech.OnInitListener() {

@Override
public void onInit(int status) {
if(status!=TextToSpeech.ERROR)
{
Toast.makeText(getBaseContext(),"Success ...",
Toast.LENGTH_LONG).show();
Log.i("Text to speech","****** Success ...");
}
else
{
Toast.makeText(getBaseContext(),"Failure ...",
Toast.LENGTH_LONG).show();
Log.i("Text to speech","******* Failure ...");
}
}
});
textToSpeech.setLanguage(Locale.UK);
}

@Override
public void onClick(View v) {
String data = (String)etInputText.getText().toString();
textToSpeech.speak(data,TextToSpeech.QUEUE_FLUSH,null);

Toast.makeText(this,data, Toast.LENGTH_LONG).show();
Log.i("TextToSpeech",data);
}
}

Output:

You might also like