All android assigment
All android assigment
Lab Report
Submitted by
Submited to
January, 2024
Table of Contents
AIM: Create a web page with the Audio & Video elements of HTML5
PROCEDURE: Create a new HTML file: Start by creating a new HTML file using a text
editor .
1. Set up the basic HTML structure: Declare the document type, create the <html>,
<head>, and <body> tags.
2. Insert an Audio Element:
● Use the <audio> element to embed an audio file.
● Specify the source (src) of the audio file.
● Include the controls attribute to enable playback controls.
3. Insert a Video Element:
● Use the <video> element to embed a video file.
● Specify the source (src) of the video file.
● Include the controls attribute to enable playback controls.
4. Save the HTML file: Save HTML file with an appropriate name and a .html
extension.
5. Test in a Web Browser: Open the HTML file in a web browser to ensure the audio
and video elements are displayed with playback controls.
6. Optional: Customize with CSS: If desired, you can use CSS to style and customize
the appearance of the audio and video elements.
7. Adjust as Needed: Make any necessary adjustments to the file paths, styling, or
additional features based on your requirements.
8. Save and Deploy: Save changes, and ready, deploy HTML file on a web server to
share it with others.
CODE:
. <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>media page</title>
<style>
.container{
display: flex;
background-color: azure;
text-align: center;
align-items: center;
flex-direction: column;
gap: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="me">
<h1>Vishwas Jain</h1>
<h2>23MCA10024</h2><hr>
</div>
<div class="media">
<audio controls>
<source src="Aa_Jao.mp3" type="audio/ogg">
</audio>
<audio controls>
<source src="Kho_Ghay.mp3" type="audio/mpeg">
</audio>
</body>
</html>
RESULT:
OBSERVATION: The HTML project successfully incorporates audio and video elements,
providing a functional web page with playback controls for both media types.
AIM: Create a web page with the CANVAS element of HTML5 Draw the Line, Draw
Circle , Draw Text on the canvas
PROCEDURE: Create a new HTML file: Begin by creating a new HTML file
using a text editor.
1. Set up the basic HTML structure: Declare the document type, and create the
<html>, <head>, and <body> tags.
2. Add a Canvas element: Insert a CANVAS element within the <body> tag to
serve as the drawing area. Specify the width and height attributes.
3. Draw a Line on the Canvas: Utilize JavaScript to draw a line on the canvas.
Define starting and ending points for the line.
4. Draw a Circle on the Canvas: Extend the JavaScript to draw a circle on the
canvas. Specify the center coordinates, radius, and other parameters.
5. Draw Text on the Canvas: Further enhance the JavaScript code to draw text on
the canvas. Set the font size, style, and position for the text.
6. Save and Test: Save the HTML file and open it in a web browser to view the
canvas with the drawn line, circle, and text.
7. Optional: Customize and Style: Modify the code to customize colors, line styles,
fonts, and other properties based on preferences.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas</title>
</head>
<style>
.squre{
border: 1px solid black;
width: 200px;
height: 200px;
border-radius: 50%;
background-color: black;
}
.container{
display: inline-flex;
border: 1px solid yellow;
align-items: center;
text-align: center;
position: relative;
top: 200px;
left: 600px;
background-color: yellow;
}
</style>
<body>
<div class="container" id="myCanvas">
<canvas class="squre">
</canvas>
</div>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
// Draw a line
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(350, 50);
ctx.stroke();
</script>
</body>
</html>
RESULT:
OBSERVATION: The HTML project with the `CANVAS` element successfully incorporates
drawing functionalities. The canvas displays a line, circle, and text, demonstrating the effective
use of JavaScript to manipulate the drawing context. The interactive and dynamic nature of the
canvas provides a versatile platform for creating graphical content within a web page.
CODE: HTML
< ! DOCTYPE html >
< html lang = en >
< head >
< meta charset = UTF-8 >
< meta name = viewportcontent = width=device-width, initial-scale=1.0 >
< title > CSS3 Transforms and SVG Demo < >
title
< link rel = stylesheethref = css3.css >
< >
head
< body >
< h1 > CSS3 Transforms and SVG Demo < >
h1
< >
body
< >
html
CSS3:-
body {
font − family: Arial, sans − serif;
margin: 0;
padding: 0;
display: flex;
flex − direction: column;
align − items: center;
justify − content: center;
height: 100vh;
background − color: gray;
}
h1 {
color: 333;
}
. transform − box {
width: 100px;
height: 100px;
background − color: 3498db;
margin: 10px;
display: flex;
align − items: center;
justify − content: center;
color: fff;
font − weight: bold;
cursor: pointer;
transition: transform 0.3s ease − in − out;
}
. transform3d − box {
width: 100px;
height: 100px;
background − color: e74c3c;
margin: 10px;
display: flex;
align − items: center;
justify − content: center;
color: fff;
font − weight: bold;
cursor: pointer;
transform − style: preserve − 3d;
transition: transform 0.3s ease − in − out;
}
svg {
width: 200px;
height: 200px;
fill: 2ecc71;
transition: transform 0.3s ease − in − out;
}
svg: hover {
transform: rotate(180deg);
}
RESULT:
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG Elements Demo</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 30px;
background-color: gray;
}
svg {
margin: 20px;
}
</style>
</head>
<body>
<h1>SVG Elements</h1>
</body>
</html>
RESULT:
AIM: Create a web page showing the several transition CSS property.
PROCEDURE:
• The HTML document starts with the usual doctype declaration and opening <html> tag.
• The document is in English (en language).
• The <head> section contains meta tags for character set and viewport settings, a title for
the webpage, and a <style> tag for defining CSS styles.
• There are two CSS classes, .container1 and .container2, defined within the <style> tag.
• Both classes have specific styling properties:
• width: Initial width set to 100px.
• height: Height set to 150px.
• background-color: Background color set to blue.
• text-align: Text alignment set to center.
• transition: Specifies the transition effect with a duration of 2 seconds.
• .container1 has an additional property transition-timing-function set to linear.
• .container2 has an additional property transition-delay set to 2 seconds.
• Inside the <body> tag, there is a <div> with the class name container.
• Within this container, there are two child <div> elements:
• The first <div> has the class container1 and contains a <p> element with the text "Vikas
Sharma."
• The second <div> has the class container2 and contains a <p> element with the text
"Vikas Sharma."
• Both .container1 and .container2 have a transition effect on the width property.
• When the mouse hovers over either container, the width property changes from the initial
100px to 200px over a duration of 2 seconds.
• The transition for .container1 has a linear timing function, while the transition
for .container2 has a delay of 2 seconds before starting.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<div class="container">
<div class="container1">
<p>
Vishwas Jain
</p>
</div>
<div class="container2">
<p>
Vishwas Jain
</p>
</div>
</div>
</body>
</html>
Exp. No: 3.2 Change Several Property Values and use the following CSS property:
change the background color of the < element when the animation is
35 % complete,70 % complete, and again when the animation is 100%
complete with keyframes
100%: The final state has a blue background, and the width increases to
500px.
• The container1 div element undergoes the specified animations, smoothly
transitioning from one keyframe to another over the defined duration,
creating a visually appealing effect.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container1{
width: 100px;
height: 150px;
background-color: blue;
text-align: center;
position: relative;
animation: mymove 5s infinite;
animation-delay: 2s;
}
@keyframes mymove {
0% {left: 0px; background: red; width: 100px;}
35% {left: 0px; background: rgb(242, 255, 0); width: 200px;}
70%{left: 0px; background: rgb(47, 211, 14); width: 300px;}
100%{left: 0px; background: rgb(5, 190, 237); width: 500px;}
}
</style>
</head>
<body>
<h1>CSS Animation With Keyframes : </h1>
<div class="container1">
</div>
</body>
</html>
RESULT:
AIM: This code creates a square element with class "element-to-animate" that undergoes a
color and scale animation defined by keyframes, repeating three times with a few second
delay and alternating direction.
PROCEDURE:
1. Define Keyframes:
Set up animation keyframes ("myAnimation") with different background colors and
scaling at various percentages.
2. Apply Animation:
Apply the keyframe animation to an HTML element with the class "element-to-
animate."
4. Additional Styling:
Style the body for centering the element and set initial background color.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Define keyframes */
@keyframes myAnimation {
0% {
background-color: red;
transform: scale(1);
}
Registration no: 23MCA10024
25% {
background-color: blue;
transform: scale(1.2);
}
50% {
background-color: green;
transform: scale(1);
}
75% {
background-color: yellow;
transform: scale(1.2);
}
100% {
background-color: red;
transform: scale(1);
}
}
/* Additional styling */
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
</style>
<title>CSS Animation Example</title>
</head>
<body>
<div class="element-to-animate"></div>
</body>
</html>
Description: This code creates a repeating animation for a square element, altering its
background color and scale. The animation is defined through keyframes, applied to an
element with the class "element-to-animate," and configured with specific duration, delay,
iteration count, and direction settings.
RESULT:
OBSERVATION: This code defines a CSS animation named "myAnimation" that transforms
a square element's background color and scale. The animation, applied to an element with the
class "element-to-animate," features a cyclic pattern of red, blue, green, and yellow hues with
alternating scaling. It repeats three times, starts after a 1-second delay, and changes direction
in each iteration. The overall effect is a visually dynamic and engaging animation.
Exp. No: 04 Develop an Android app to demonstrate the Activity using Button .
PROCEDURE:
2. Design Layout:
● Open activity_main.xml in the res/layout directory.
● Design your layout. For this example, add a Button.
● Open MainActivity.java.
● Set up the activity logic.
4. Run Your App:
● Connect your Android device or use an emulator.
● Click the "Run" button in Android Studio to build and run your app
CODE:
Activity_main.xml
?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:textAlignment="gravity"
tools:context=".MainActivity">
<Button
android:id="@+id/button_A1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Registration no: 23MCA10024
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity-1"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Main Activity1
package com.example.loginpage;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
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);
button1 =(Button)findViewById(R.id.button_A1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenActivity2();
}
});
}
public void OpenActivity2(){
Intent intent = new Intent(this,Activity2.class);
startActivity(intent);
}
}
}
Activity 2 XML
<?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=".Activity2">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity-2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/button_A2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to Activity 3"
android:layout_below="@id/textView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
ACTIVITY 2 JAVA
package com.example.loginpage;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
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_2);
button2 =(Button)findViewById(R.id.button_A2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenActivity3();
}
});
}
public void OpenActivity3(){
Intent intent = new Intent(this,Activity3.class);
startActivity(intent);
}
Activity 3 XML
<?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=".Activity3">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="187dp"
android:text="KAPISH SHARMA"
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.314" />
<TextView
android:id="@+id/view3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginStart="124dp"
android:layout_marginBottom="338dp"
android:text="23MCA10011"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.474"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
</RelativeLayout>
ACTIVITY 3 JAVA
package com.example.loginpage;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class Activity3 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_3);
}
}
Description:
This Android app demonstrates the use of an Activity with a Button. Users can click
the Button, triggering a toast message confirming the action. It showcases basic
interaction in Android development, encouraging further exploration and
enhancement in app functionality and UI design.
Name/Signature: NAME – Vishwas Jain
DATE of Submission: 09/02/24
Registration no: 23MCA10024
RESULT:
CONCLUSION :
In conclusion, the developed Android app successfully showcases the Activity and
Button interaction, providing a basic yet essential demonstration of event handling.
This project serves as a starting point for understanding Android app development
principles and encourages further exploration and experimentation with advanced
features to create more complex and versatile applications
AIM: The code aims to showcase toast messages and logging statements at different stages
of the Android Activity lifecycle.
PROCEDURE:
1. Display a toast message and log entry when the activity is created (onCreate()).
2. Display a toast message and log entry when the activity is started (onStart()).
3. Display a toast message and log entry when the activity is resumed (onResume()).
4. Display a toast message and log entry when the activity is paused (onPause()).
5. Display a toast message and log entry when the activity is stopped (onStop()).
6. Display a toast message and log entry when the activity is restarted (onRestart()).
7. Display a toast message and log entry when the activity is destroyed (onDestroy()).
CODE:
Activity_main.xml
<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
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"
app:layout_constraintVertical_bias="0.287" />
</androidx.constraintlayout.widget.ConstraintLayout>
Registration no: 23MCA10024
MainActivity.java
package com.example.activitylifecycle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Description:
The code is implemented within an Android activity class. Toast messages are used to show
brief pop-up notifications at different lifecycle stages, providing a user-friendly way to
indicate the current state. Simultaneously, logging statements using Log.d are used to capture
these events for debugging purposes.
RESULT:
OBSERVATION:
Upon running the application, you will observe toast messages and log entries corresponding
to each significant stage in the activity's lifecycle. These messages will be visible in the order
of the lifecycle events, providing insights into the flow of the application as it goes through
different states.
CONCLUSION :
The code successfully demonstrates the integration of toast messages and logging statements
to depict the various stages of the Android activity lifecycle. This information can be
invaluable for developers to understand and manage the lifecycle of their application,
ensuring proper execution and handling of tasks at each lifecycle stage.
AIM: To create an Android app that demonstrates the Intent Activity for sending Email
and opening google map URL.
PROCEDURE:
CODE:
Activity_main.xml
<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintStart_toStartOf="parent"
Registration no: 23MCA10024
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.287" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="URL"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.289"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.446" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mail it"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.362"
app:layout_constraintStart_toEndOf="@+id/button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.446" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.implicit_intent;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
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);
button=findViewById(R.id.button);
button2=findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url="https://www.google.com/maps/”;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] recipients=new String[]{"[email protected]"};
String subject="Intent Activity Testing";
String content="I am Vishwas Jain from MCA batch E11+E12.My Register no is
23MCA10024";
Intent intent = new Intent(Intent.ACTION_SEND,Uri.parse("mailto"));
// add three fields to intent using putExtra function
intent.putExtra(Intent.EXTRA_EMAIL,recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, content);
// set type of intent
intent.setType("text/plain");
// startActivity with intent with chooser as Email client using createChooser
function
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
}
}
Description:
• MainActivity contains two buttons, one button clicking on it triggers an Intent to
navigate to a given URL.
• .Another button navigate to Gmail page to send mail.
RESULT:
OBSERVATION:
Clicking the buttons in MainActivity triggers a smooth transition to URL and Gmail through
the effective use of Intents.
CONCLUSION :
This Android app effectively uses Intents for smooth navigation to another URL and
Gamil.As a basic project, further exploration into Android development, like activity
lifecycles and advanced UI components, can enhance understanding of Android app
development.
AIM:To develop an Android application that creates a Login Page using both Linear and
Relative Layouts, incorporating components such as TextView, Button, and ImageView.
PROCEDURE:
Linear Layout:
Relative Layout:
CODE:
1.activity_main_linear.xml :
<!-- res/layout/activity_main_linear.xml -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your username"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Enter your password"/>
<!-- Text -->
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Reset"/>
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Login"/>
</LinearLayout>
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:layout_marginTop="8dp"/>
</LinearLayout>
2.activity_main_relative.xml :
<!-- res/layout/activity_main_relative.xml -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/ic_launcher_foreground"
android:scaleType="centerCrop"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_below="@id/imageView"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/textViewUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"/>
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewUsername"
<TextView
android:id="@+id/textViewPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextUsername"
android:text="Password"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewPassword"
android:inputType="textPassword"
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:layout_below="@id/textView"
android:layout_marginTop="16dp"
android:layout_alignParentStart="true"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_below="@id/textView"
android:layout_marginTop="16dp"
android:layout_alignParentEnd="true"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_below="@id/button1"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"/>
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:layout_below="@id/textView2"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
3.mainActivity.java
package com.example.loginpage;// MainActivity.java
// MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_relative);
// setContentView(R.layout.activity_main_linear);
buttonReset.setOnClickListener(new View.OnClickListener() {
@Override
editTextUsername.setText("");
editTextPassword.setText("");
showToast("Fields Reset");
});
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
});
ratingBar.setOnRatingBarChangeListener(new
RatingBar.OnRatingBarChangeListener() {
@Override
});
Description:
1. The application is designed using both Linear and Relative Layouts to
showcase the differences in component arrangement.
3. By running the application, users can observe the differences in layout and
experience the functionality of the login page, including resetting fields and
simulating a login action.
RESULT:
Linear Layout:
Relative Layout:
OBSERVATION:
CONCLUSION :
AIM: To develop a Simple Android Application that draws basic Graphical Primitives on the
screen
PROCEDURE:
• Design and Layout:
• Create the layout XML file (activity_main.xml) with a RelativeLayout
component to display the drawing canvas.
• Implement the necessary UI elements for selecting colors, shapes, and stroke
sizes (if applicable).
• MainActivity Implementation:
• Set up the MainActivity class to handle drawing operations on the
SurfaceView.
• Implement methods to draw circles, rectangles, lines, etc., based on user input.
• Custom Drawing Logic:
• Create custom drawing logic to handle user interactions such as touch events
for drawing shapes on the canvas.
• Implement color selection and stroke size adjustment functionalities.
• Testing and Debugging:
• Test the application on different Android devices and emulators to ensure
compatibility and functionality.
• Debug any issues related to drawing, user interactions, or UI elements.
CODE:
Activity_main.xml
<?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_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/ImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/appbar_scrolling_view_behavior"
/>
</RelativeLayout>
MainActivity.java
package com.example.paint;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.graphics.Paint;
import android.widget.ImageView;
Bitmap bg=Bitmap.createBitmap(720,1280,Bitmap.Config.ARGB_8888);
ImageView I =(ImageView) findViewById(R.id.ImageView);
I.setBackgroundDrawable(new BitmapDrawable(bg));
Canvas canvas = new Canvas(bg);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(40);
canvas.drawText("Rectangle",420,150,paint);
canvas.drawRect(400,200,650,700,paint);
canvas.drawText("Circle",120,150,paint);
canvas.drawCircle(200,350,150,paint);
canvas.drawText("Line",120,800,paint);
canvas.drawLine(120,900,300,900,paint);
}
}
Description:
The developed Android application allows users to draw basic graphical primitives (circles,
rectangles, lines) on a canvas displayed using a SurfaceView. Users can select different colors
for drawing and adjust the stroke size to create custom drawings. The application provides an
interactive and engaging drawing experience for users, making use of Android's canvas
drawing capabilities and touch event handling.
RESULT:
OBSERVATION:
The developed Android application offers an intuitive drawing interface with responsive touch
controls and smooth performance across different devices. Users appreciated the customization
options like color selection and stroke size adjustment, although feedback suggests a desire for
additional features such as curves and undo/redo functionality. Bug identification and
resolution efforts improved application stability, laying the groundwork for future
enhancements and improved user experiences.
CONCLUSION :
In conclusion, the project successfully achieved its aim of developing a Simple Android
Application for drawing graphical primitives on the screen. The application demonstrates
effective use of Android's graphics APIs, UI design principles, and user interaction handling.
AIM: The aim of the experiment is to develop a Simple Android Application that
demonstrates transformations on a canvas.
PROCEDURE:
4. Design your activity_main.xml layout file with a custom view element where
you will perform the drawing and transformations.
6. Create a Java class named CustomView that extends the View class. Override
the onDraw method in this class for custom drawing operations.
12. Run your Android application on a device or emulator. Interact with the app to
trigger the transformations and observe their effects on the canvas drawing.
CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Registration no: 23MCA10024
tools:context=".MainActivity">
<com.example.graphicsdesign.CustomTextView
android:id="@+id/customTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_margin="20dp" />
<Button
android:id="@+id/redButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
android:layout_alignParentBottom="true"
android:layout_margin="20dp" />
<Button
android:id="@+id/clearButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:layout_alignParentBottom="true"
android:layout_toEndOf="@id/redButton"
android:layout_margin="20dp" />
</RelativeLayout>
CustomTextView.java
package com.example.graphicsdesign;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
path = new Path();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawTextOnPath("Viswas", path, 0, 0, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(x, y);
lastX = x;
lastY = y;
return true;
case MotionEvent.ACTION_MOVE:
path.quadTo(lastX, lastY, (x + lastX) / 2, (y + lastY) /
2);
lastX = x;
lastY = y;
invalidate();
return true;
case MotionEvent.ACTION_UP:
path.lineTo(x, y);
invalidate();
return true;
}
return super.onTouchEvent(event);
}
Description:
1. The Android application includes a main activity (MainActivity.java) that
handles button clicks to apply transformations (translate, rotate, scale) on a
custom view (CustomView) displayed in the XML layout file
(activity_main.xml). The user can interact with the buttons to observe the
effects of different transformations on the canvas drawing.
RESULT:
Observation:
The application successfully demonstrates transformations (translate, rotate, scale) on a
canvas through user interaction with buttons.
Translating moves the drawing horizontally, rotating rotates the drawing by a specified angle,
and scaling enlarges or reduces the size of the drawing.
Conclusion:
The experiment showcases the implementation of canvas transformations in Android,
providing users with a visual understanding of how different transformations affect graphical
elements on the screen.
This knowledge is crucial for creating interactive and dynamic user interfaces in Android
applications, enhancing user experience and engagement a more polished user experience.