You are on page 1of 4

Mobile Application Development (22617)

Name : Ashwin Pawar Practical No : 25


Roll No : 23

Develop a program for animation. a program to build Ca Develop


a program for providing Bluetooth connectivity.
X. Exercise.
1. Write a program to rotate the image in
clockwise/anticlockwise, Zoom IN/Zoom OUT, Fade
IN/Fade OUT by using the following
GUI.AndroidManifiest.xml file

Pr25java file
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;

public class pr25 extends AppCompatActivity {

private ImageView imageView;

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

imageView = findViewById(R.id.imageView);

Button rotateClockwiseButton =
findViewById(R.id.rotateClockwiseButton);
rotateClockwiseButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
rotateClockwise();
}
});

Button rotateAntiClockwiseButton =
findViewById(R.id.rotateAntiClockwiseButton);
rotateAntiClockwiseButton.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
rotateAntiClockwise();
}
});
Mobile Application Development (22617)

Button zoomInButton = findViewById(R.id.zoomInButton);


zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomIn();
}
});

Button zoomOutButton = findViewById(R.id.zoomOutButton);


zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomOut();
}
});

Button fadeInButton = findViewById(R.id.fadeInButton);


fadeInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fadeIn();
}
});

Button fadeOutButton = findViewById(R.id.fadeOutButton);


fadeOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fadeOut();
}
});
}

private void rotateClockwise() {


imageView.setRotation(imageView.getRotation() - 90);
}

private void rotateAntiClockwise() {


imageView.setRotation(imageView.getRotation() + 90);
}

private void zoomIn() {


imageView.setScaleX(imageView.getScaleX() * 1.5f);
imageView.setScaleY(imageView.getScaleY() * 1.5f);
}

private void zoomOut() {


imageView.setScaleX(imageView.getScaleX() * 0.5f);
imageView.setScaleY(imageView.getScaleY() * 0.5f);
}

private void fadeIn() {


imageView.animate().alpha(1).setDuration(1000);
}

private void fadeOut() {


imageView.animate().alpha(0).setDuration(1000);
}
}
Mobile Application Development (22617)

Pr25.xml file
<?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"
tools:context=".pr25">
<ImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/animation" />
<Button
android:id="@+id/rotateClockwiseButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rotate Clockwise"
android:layout_below="@id/imageView"
android:layout_marginTop="40dp"/>

<Button
android:id="@+id/rotateAntiClockwiseButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rotate Anti-clockwise"
android:layout_below="@id/rotateClockwiseButton"
android:layout_marginTop="10dp"/>

<Button
android:id="@+id/zoomInButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Zoom In"
android:layout_below="@id/rotateAntiClockwiseButton"
android:layout_marginTop="10dp"/>

<Button
android:id="@+id/zoomOutButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Zoom Out"
android:layout_below="@id/zoomInButton"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/fadeInButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fade In"
android:layout_below="@id/zoomOutButton"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/fadeOutButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fade Out"
android:layout_below="@id/fadeInButton"
android:layout_marginTop="10dp"/>

</RelativeLayout>
Mobile Application Development (22617)

You might also like