Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views87 pages

Android 50

Uploaded by

muhammedlatheef
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)
21 views87 pages

Android 50

Uploaded by

muhammedlatheef
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/ 87

Exp No : 1 INSTALL ANDROID STUDIO

Date :

Aim : To install Android Studio.

Procedure :

Step 1: Download Android Studio


1. Visit the official Android Studio website at https://developer.android.com/studio.

2. Click on the “Download android studio” button.


3. Choose the appropriate version of your operating system (Windows, MacOS, or Linux).
4. Follow the on-screen instructions to begin the download.

Step 2: Install Android studio


1. Once the download is complete, locate the downloaded file and double-click to start
the installation process.

2. Follow the setup wizard’s instructions to install Android Studio on your computer.
3. Choose the installation location and add any additional components you want to
install (such as Android Virtual Device)

4. Click “Next” to proceed with the installation.

5. Review the installation settings and click “Install” to begin the installation process.
6. Wait for the installation to complete. This may take some time depending on your
system specifications.

Step 3: Configure Android studio


1. After the installation is complete, launch android studio from the start menu (Windows)
or the application folder (MacOs).

2. On the welcome screen, click “Configure” and the select “SDK Manager”.
3. In the SDK Manager, install the necessary SDK components for the Android versions
you intend to target.

4. Next, configure the SDK location by clicking on “Configure” >”Project Defaults”>”Project


Structures”.

5. Specify the location of the Android SDK by clicking on the “SDK Location” field and
browsing to the SDK directory.

6. Click “Ok” to save the settings.

Step 4: Set up Android Emulator (Optional)

1. To test your apps, you can set up an android emulator by clicking on “Configure”>”AVD
Manager”.

2. In the AVD Manager, click “Create Virtual Device”.

3. Choose a hardware profile and system image for the emulator and click “Next”.

4. Configure the emulator settings such as RAM size, and storage and click “Finish”.

5. Once the emulator is created, select it from the AVD Manager and click “Start” to launch
the emulator.

Step 5: Verify installation


1. To verify that Android Studio is installed correctly, create a new android project.

2. Go to “File”>”New”>”New Project” and follow the project creation wizard.


3. Once the project is created, Android Studio will open with your project loaded.

4. Run the project by clicking on the “Run” button (green triangle) in the toolbar.
5. If the project builds successfully and launches on the emulator or connected device,
Android Studio is installed and configured correctly.
Output :

Result:
Thus the Android Studio application has been installed successfully.
Exp No : 2

SIMPLE DESIGN LAYOUT

Date :

Aim :
To implement the Simple design layout in Android Studio.

Algorithm :
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=".MainActivity2">

<TextView android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="268dp"
android:layout_marginEnd="88dp"
android:text="NAME : "
android:textSize="30dp" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="64dp" android:layout_marginTop="52dp"
android:text="RRN : "
android:textSize="30dp" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" /> <ImageView
android:id="@+id/imageView" android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="@drawable/profile"
tools:layout_editor_absoluteX="56dp" tools:layout_editor_absoluteY="49dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

Java :
package com.example.myapplication; import
androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
public class MainActivity2 extends AppCompatActivity { @Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2);
}}
Output :

Result :
Thus to implement the applications to show GUI components in Android Studio have been
executed successfully.
Exp No : 3 IMPLICIT AND EXPLICIT

Date :

Aim :
To implement the implicit and explicit in Android Studio.

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

<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="
page
1" tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="140dp"
tools:layout_editor_absoluteY="157dp" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=" page
2" tools:layout_editor_absoluteX="171dp"
tools:layout_editor_absoluteY="559dp" />

<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to go to login 2"
android:textColor="#FFC107"
android:textSize="20dp"
android:textStyle="italic" tools:layout_editor_absoluteX="87dp"
tools:layout_editor_absoluteY="442dp" />

<TextView android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to go to page 1"
android:textColor="#FFC107"
android:textSize="20dp"
android:textStyle="italic" tools:layout_editor_absoluteX="94dp"
tools:layout_editor_absoluteY="110dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity-2
<?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=".MainActivity2">

<TextView android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="252dp" android:layout_marginEnd="220dp"
android:text="NAME : " android:textSize="30dp" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="84dp"
android:text="RRN : " android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id
/textView4" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java file : Java-1 package


com.example.myapplication;

import androidx.activity.result.contract.ActivityResultContracts; 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;
public class MainActivity extends AppCompatActivity {
Button b1,b2; @Override protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1 = (Button) findViewById(R.id.button); b2
= (Button) findViewById(R.id.button2);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cs = new Intent(MainActivity.this, MainActivity2.class);
startActivity(cs);
}
});

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cse = new Intent(Intent.ACTION_VIEW);
cse.setData(Uri.parse("https://www.youtube.com/")); startActivity(cse); }
});

}
}
Java-2 package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity2 extends AppCompatActivity {

@Override protected void onCreate(Bundle


savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}}
Output :

Result :
Thus to implement the implicit and explicit in Android Studio have been executed
successfully.
Exp No : 4 CALCULATOR

Date :

Aim :

To implement calculator in Android Studio.

Algorithm :
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:padding="20dp"
tools:context=".MainActivity">

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginBottom="16dp"
android:text=" CALC"
android:textStyle="bold" android:textColor="#FFEB3B" android:textSize="25sp"
/>

<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">

<EditText android:id="@+id/first_no"
android:layout_width="102dp" android:layout_height="59dp"
android:layout_marginHorizontal="50dp"
android:ems="10"
android:hint="Enter" />

<EditText
android:id="@+id/second_no"
android:layout_width="102dp"
android:layout_height="59dp"
android:ems="10"
android:hint="Enter" />

</LinearLayout>

<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">

<TextView android:id="@+id/answer"
android:layout_width="wrap_content" android:layout_height="77dp"
android:layout_marginHorizontal="50dp" android:hint="ANSWER"
android:textSize="35sp" />

</LinearLayout>

<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="250dp"
android:layout_marginBottom="30dp"
android:orientation="vertical">

<Button android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="+" android:textSize="25sp"
tools:ignore="OnClick" />

<Button android:id="@+id/sub"
android:layout_width="wrap_content"

android:layout_height="wrap_content" android:layout_marginBottom="16dp"
android:text="-"
android:textSize="25sp" />

<Button android:id="@+id/div" android:layout_width="wrap_content"


android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="/" android:textSize="25sp" />

<Button android:id="@+id/mul"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:text="X"
android:textSize="25sp" />

<Button android:id="@+id/equals"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="=" android:textSize="35sp" />
</LinearLayout> </LinearLayout>

Java :
package com.example.calculartor_sr;
import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

EditText no1 , no2;


Button add ,mul ,div , sub,equal; TextView answer;
double ans = 0;

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

// for text views no1 = findViewById(R.id.first_no);


no2 = findViewById(R.id.second_no);

// for button with operations add =


findViewById(R.id.add); mul =
findViewById(R.id.mul); div =
findViewById(R.id.div);
sub = findViewById(R.id.sub);

// for equal to button equal =


findViewById(R.id.equals);

// for answer field answer = findViewById(R.id.answer);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();

if (num1.isEmpty() || num2.isEmpty()) {

Toast.makeText(getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
} else
{ double a =
Double.parseDouble(no1.getText().toString()); double b
=
Double.parseDouble(no2.getText().toString()); ans =
a + b;
}
}
});
sub.set
OnClick
Listener
(new
View.O
nClickLi
stener()
{
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();

if (num1.isEmpty() || num2.isEmpty()) {

Toast.makeText(getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
} else {
double a =
Double.parseDouble(no1.getText().toString());
double b
=
Double.parseDouble(no2.getText().toString()); ans =
a - b;
}
}
});

mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();

if (num1.isEmpty() || num2.isEmpty()) {

Toast.makeText(getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
} else
{ double a =
Double.parseDouble(no1.getText().toString()); double b
=
Double.parseDouble(no2.getText().toString()); ans =
a * b;
}
}
});

div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();

if (num1.isEmpty() || num2.isEmpty()) {
Toast.makeText(getApplicationContext(),
"Enter Numbers", Toast.LENGTH_SHORT).show();
} else { double a
=
Double.parseDouble(no1.getText().toString()); double b
=
Double.parseDouble(no2.getText().toString()); if
(b != 0) ans = a / b;
else
Toast.makeText(getApplicationContext(), "Enter Valid Numbers",
Toast.LENGTH_SHORT).show();
}
}
});

equal.setOnClickListener(new View.OnClickListener() {
@Override public void
onClick(View v) {
String ans1 = String.valueOf(ans);

answer.setText(ans1);
ans= 0;
}
});

}}
Output :

Result :
Thus to implement calculator in Android Studio have been executed successfully.
Exp No : 5

Vertical and Horizontal Scroll View Layout

Date :

Aim :
To implement scroll bar in Android Studio.

Algorithm :
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:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="16dp"
android:text="Vertical ScrollView"
android:textColor="#304FFE" android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ScrollView android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="250dp" android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2">

<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4E599" android:padding="10dp"
android:text="string/This"
android:textSize="24sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/is"
android:textSize="24sp" />

<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp"
android:text="@string/a" android:textSize="24sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/vertical"
android:textSize="24sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_marginTop="10dp"
android:background="#F4E599" android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#F4E599"
android:padding="10dp" android:text="@string/This"
android:textSize="24sp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:background="#F4E599"
android:padding="10dp"
android:text="@string/is" android:textSize="24sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/a"
android:textSize="24sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/vertical"
android:textSize="24sp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />
</LinearLayout>

</ScrollView>

<TextView android:id="@+id/textView127" android:layout_width="wrap_content"


android:layout_height="wrap_content" android:layout_marginTop="32dp"
android:text="Horizontal ScrollView" android:textColor="#304FFE"
android:textSize="24sp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scrollVi ew2" />

<HorizontalScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView127">

<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/This"
android:textSize="24sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/is" android:textSize="24sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5" android:padding="10dp"
android:text="@string/a" android:textSize="24sp" />

<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:background="#5BBAF5"
android:padding="10dp" android:text="@string/horizontal"
android:textSize="24sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:background="#5BBAF5"
android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/This"
android:textSize="24sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/is"
android:textSize="24sp" />

<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:background="#5BBAF5"
android:padding="10dp" android:text="@string/a"
android:textSize="24sp" />

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp"
android:text="@string/horizontal"
android:textSize="24sp" />

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />

</LinearLayout>

Java:
package com.example.scrollbar033;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override protected void onCreate(Bundle


savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
}}
Output :

Result : Thus to implement scroll bar in Android Studio have been executed successfully.
Exp No : 6
Implementation of Rating Bar

Date :

Aim :
To implement rating bar in Android studio.

Algorithm :
Xml :
<!-- res/layout/activity_main.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"
tools:context=".MainActivity">

<RatingBar android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:numStars="5" android:rating="2.5"
android:stepSize="0.5"/>

<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ratingBar"
android:layout_centerHorizontal="true" android:layout_marginTop="16dp"
android:text="Submit Rating"/>

<TextView
android:id="@+id/textRating"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/btnSubmit"
android:layout_centerHorizontal="true" android:layout_marginTop="16dp"
android:text="Rating: N/A"/> </RelativeLayout> Java
:

package com.example.ratingapp;

import android.os.Bundle; import


android.view.View; import android.widget.Button;
import android.widget.RatingBar; import
android.widget.TextView; import
android.widget.Toast; import
androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

RatingBar ratingBar;
Button btnSubmit;
TextView textRating;
@Override protected void onCreate(Bundle
savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ratingBar = findViewById(R.id.ratingBar); btnSubmit


= findViewById(R.id.btnSubmit); textRating
= findViewById(R.id.textRating);

btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) { float
currentRating = ratingBar.getRating();
textRating.setText("Rating:
" + currentRating);
Toast.makeText(MainActivity.this, "Submitted Rating: " + currentRating,
Toast.LENGTH_SHORT).show();
}
});

ratingBar.setOnRatingBarChangeListener(new
RatingBar.OnRatingBarChangeListener() {
@Override public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// Update the rating as the user changes it textRating.setText("Rating:
" + rating);
}
});
}}
Output :

Result :
Thus to implement the rating app in Android Studio have been executed successfully.
Exp No : 7
Display of Toast Message

Date :

Aim :
To implement Display of Toast Message in Android Studio.

Algorithm :
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" tools:context=".MainActivity">

<Button

android:id="@+id/btnShowToast" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:text="Show

Toast" android:layout_centerInParent="true"/>

</RelativeLayout> Java

:
package com.example.myapplication; // Replace this with your package name

import androidx.appcompat.app.AppCompatActivity; import


android.os.Bundle; import

android.view.View; import

android.widget.Button; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override protected void onCreate(Bundle savedInstanceState)


{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnShowToast = findViewById(R.id.btnShowToast);
btnShowToast.setOnClickListener(new View.OnClickListener() {
@Override public void
onClick(View v) {
// Display a toast message when the button is clicked
Toast.makeText(getApplicationContext(), "Hello, Toast!",
Toast.LENGTH_SHORT).show();
}
});
}
}
Output :

Result :
Thus to implement toggle button in Android Studio have been executed successfully.
Exp No : 8 IMPLEMENTATION OF TOGGLE BUTTON

Date :

Aim :
To implement toggle button in Android Studio.

Algorithm :
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=".MainActivity">

<ToggleButton android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:layout_marginLeft="150dp"
android:text="Toggle 1" />

<ToggleButton android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle 2"
android:layout_below="@id/toggleButton1"
android:layout_marginTop="50dp" android:layout_marginLeft="150dp"
android:layout_centerHorizontal="true"/>

<TextView
android:id="@+id/outputTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/toggleButton2"
android:layout_marginTop="16dp" android:layout_centerHorizontal="true"/>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="75dp"
android:layout_marginLeft="130dp"
android:textStyle="bold"
android:textSize="30dp" android:text="Toggle
Button" />

<ImageView android:id="@+id/imageView"
android:layout_width="180dp"
android:layout_height="122dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="450dp"
app:srcCompat="@drawable/toggle" />
</RelativeLayout>

Java :
package com.example.togglebtn033;

import androidx.appcompat.app.AppCompatActivity; import


android.os.Bundle; import android.view.View; import
android.widget.CompoundButton; import
android.widget.TextView; import
android.widget.ToggleButton;
import android.util.TypedValue;

public class MainActivity extends AppCompatActivity {

private ToggleButton toggleButton1, toggleButton2; private


TextView outputTextView; private StringBuilder stringBuilder;

@Override protected void onCreate(Bundle


savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

toggleButton1 = findViewById(R.id.toggleButton1); toggleButton2 =


findViewById(R.id.toggleButton2); outputTextView =
findViewById(R.id.outputTextView); stringBuilder = new StringBuilder();

toggleButton1.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { updateOutputText();
}
});

toggleButton2.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { updateOutputText();
}
});
}

private void updateOutputText() {


stringBuilder.setLength(0); // Clear the StringBuilder
if (toggleButton1.isChecked()) { stringBuilder.append("Toggle 1 is ON\n");
outputTextView.setTextColor(getResources().getColor(R.color.onColor)); // Change color
for ON
} else {
stringBuilder.append("Toggle 1 is OFF\n");
outputTextView.setTextColor(getResources().getColor(R.color.offColor)); // Change
color for OFF
}

if (toggleButton2.isChecked()) { stringBuilder.append("Toggle 2 is ON");


outputTextView.setTextColor(getResources().getColor(R.color.onColor)); // Change color
for ON
} else {
stringBuilder.append("Toggle 2 is OFF");
outputTextView.setTextColor(getResources().getColor(R.color.offColor)); // Change
color for OFF
}
outputTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); // Adjust the size as
needed

outputTextView.setText(stringBuilder.toString());
}

}
Output :

Result :
Thus to implement toggle button in Android Studio have been executed successfully.
Exp No : 9 IMPLEMENTATION OF CHECK BOX

Date :

Aim :
To implement check box in Android Studio.

Algorithm :
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"
android:padding="16dp"
tools:context=".MainActivity">

<CheckBox android:id="@+id/checkboxOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="150dp"
android:checked="false" android:text="Java" />

<CheckBox android:id="@+id/checkboxOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="Kotlin" android:checked="false"
android:layout_below="@id/checkboxOption1"
android:layout_marginTop="16dp"/>

<CheckBox android:id="@+id/checkboxOption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="Swift" android:checked="false"
android:layout_below="@id/checkboxOption2"
android:layout_marginTop="16dp"/>

<Button android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="Submit"
android:backgroundTint="#D32626"
android:textStyle="bold"
android:layout_below="@id/checkboxOption3" android:layout_marginTop="16dp"/>

<TextView android:id="@+id/textView"
android:layout_width="221dp"
android:layout_height="69dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="70dp"
android:text=" Checkbox"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="25sp"
android:textStyle="bold" />

</RelativeLayout>

Java :
import android.os.Bundle; import android.view.View; import
android.widget.Button; import android.widget.CheckBox;
import android.widget.Toast; import
androidx.appcompat.app.AppCompatActivity; public class
MainActivity extends AppCompatActivity {
private CheckBox checkboxOption1, checkboxOption2, checkboxOption3; private Button
submitButton;

@Override protected void onCreate(Bundle


savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
checkboxOption1 = findViewById(R.id.checkboxOption1); checkboxOption2 =
findViewById(R.id.checkboxOption2); checkboxOption3 =
findViewById(R.id.checkboxOption3); submitButton =
findViewById(R.id.submit_button);

submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder message = new StringBuilder("Selected options: ");
if (checkboxOption1.isChecked()) {
message.append("Option 1, ");
}
if (checkboxOption2.isChecked()) {
message.append("Option 2, ");
}
if (checkboxOption3.isChecked()) { message.append("Option 3");
}
// Remove the trailing comma and space if
(message.charAt(message.length() - 2) == ',') {
message.delete(message.length() - 2, message.length());
}
Toast.makeText(MainActivity.this, message.toString(),
Toast.LENGTH_SHORT).show();
}
});
}}
Output :

Result :
Thus to implement check box in Android Studio have been executed successfully.
Exp No : 10 IMPLEMENTATION OF ANIMATION

Date :

Aim :
To implement animation in Android Studio.

Algorithm :
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"
tools:context=".MainActivity">

<Button android:id="@+id/btnAnimate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_marginTop="20dp"
android:text="Animate" />

<ImageView android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnAnimate"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@drawable/ic_launcher_foreground" />

</RelativeLayout>

Java:
package com.example.animation_md;

import android.os.Bundle; import


android.view.View; import android.view.animation.Animation; import
android.view.animation.RotateAnimation; import
android.widget.Button; import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private ImageView imageView; private


Button btnAnimate;

@Override protected void onCreate(Bundle


savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView); btnAnimate =
findViewById(R.id.btnAnimate);
btnAnimate.setOnClickListener(new View.OnClickListener() {
@Override public void
onClick(View v) { animateClockwise();
}
});
}

private void animateClockwise() {


RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(1000);
imageView.startAnimation(rotateAnimation);

rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationStart(Animation
animation) {}

@Override
public void onAnimationEnd(Animation animation) {
animateAntiClockwise();
}

@Override
public void onAnimationRepeat(Animation animation) {}
});
}

private void animateAntiClockwise() {


RotateAnimation rotateAnimation = new RotateAnimation(360, 0,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(1000);
imageView.startAnimation(rotateAnimation); }}
Output :

Result :
Thus to implement animation in Android Studio have been executed successfully.
Exp No : 11 FRAGMENT (MULTI-THREADING)

Date :

Aim :
To implement Fragments in Android Studio.

Algorithm :
Xml :
<?xml version="1.0" encoding="utf8"?>
<RelativeLayout xmlns:android="http:
//schemas.android.c
om/apk/res/android"

xmlns:tools="http://s
chemas.android.co
m/tools"

android:layout_widt h="match_parent"

android:layout_heig ht="match_parent"

tools:context=".Main Activity">

<FrameLayout

android:id="@+id/fra gmentContainer"
android:layout_widt h="match_parent"

android:layout_heig ht="match_parent"

android:layout_abov
e="@+id/buttonCont
ainer"

android:layout_align ParentTop="true"
/>

<LinearLayout android:id="@+id/bu ttonContainer"

android:layout_widt h="match_parent"

android:layout_heig ht="wrap_content"

android:layout_align ParentBottom="true"
android:orientation= "horizontal">

<Button

android:id="@+id/bt
nFragment1"
android:layout_widt h="0dp"

android:layout_heig ht="wrap_content"

android:layout_weig ht="1"

android:text="Fragm ent
1" />

<Button

android:id="@+id/bt nFragment2"
android:layout_widt h="0dp"

android:layout_heig ht="wrap_content"

android:layout_weig ht="1"

android:text="Fragm
ent 2" />
</LinearLayout>

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

android:layout_width=
"match_parent"
android:layout_height ="match_parent"

android:gravity="cente
r"

android:orientation="v ertical">

<TextView

android:layout_width= "wrap_content"

android:layout_height ="wrap_content"
android:text="Fragme nt 1"

android:textSize="24s p"
/>

</LinearLayout>

fragment_two.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment 2"
android:textSize="24sp" />

</LinearLayout>

FragmentOne.java:

package com.example.myapplication;
import android.os.Bundle; import
android.view.LayoutInflater; import
android.view.View; import
android.view.ViewGroup;
import androidx.fragment.app.Fragment;

public class FragmentOne extends Fragment {

public FragmentOne() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_one, container, false);
}
}

FragmentTwo.java:

package com.example.myapplication;

import android.os.Bundle; import


android.view.LayoutInflater; import
android.view.View; import
android.view.ViewGroup;
import androidx.fragment.app.Fragment;

public class FragmentTwo extends Fragment

public FragmentTwo() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_two, container, false);
}
}
MainActivity.java:

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import
androidx.fragment.app.FragmentManager; import
androidx.fragment.app.FragmentTransaction; import
android.os.Bundle; import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

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

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


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

btnFragment1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFragment(new FragmentOne());
}
});

btnFragment2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFragment(new FragmentTwo());
}
});
}

private void loadFragment(Fragment fragment) {


FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragmentContainer, fragment);
fragmentTransaction.addToBackStack(null); // Optional: Adds the transaction to
the back stack
fragmentTransaction.commit();
}
}
OUTPUT:

Result :
Thus to implement animation in Android Studio have been executed successfully.
Exp No : 12 RSS FEEDS

Date :

Aim :
To implement RSS Feeds in Android Studio.

Algorithm :
Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<Button
android:id="@+id/btnRediff"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="101dp"
android:text="REDIFF RSS FEED" />

<Button
android:id="@+id/btnCinemaBlend"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnRediff"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/btnRediff"
android:layout_marginBottom="28dp" android:text="CINEMA
BLEND RSS FEED" />
</RelativeLayout>

MainActivity.java:

package example.javatpoint.com.androidrssfeed;
import android.support.v7.app.AppCompatActivity; import
android.os.Bundle; import
android.content.Intent; import android.view.View;
import android.widget.Button; import
java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

ArrayList<String> rssLinks = new ArrayList<>();


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

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


Button btnCinemaBlend = findViewById(R.id.btnCinemaBlend);
btnRediff.setOnClickListener(this); btnCinemaBlend.setOnClickListener(this);
rssLinks.add("http://www.rediff.com/rss/moviesreviewsrss.xml");
rssLinks.add("http://www.cinemablend.com/rss_review.php");
}
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), RSSFeedActivity.class);
switch (view.getId()) { case R.id.btnRediff:
intent.putExtra("rssLink", rssLinks.get(0)); startActivity(intent); break;
case R.id.btnCinemaBlend:
intent.putExtra("rssLink", rssLinks.get(1)); startActivity(intent);
break;
}
}
}

rss_item_list_row.xml:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="8dip">

<TextView android:id="@+id/page_url"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />

<TextView
android:id="@+id/title" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="1dip"
android:textColor="#212121" android:textSize="18sp"
android:textStyle="bold" />

<TextView
android:id="@+id/pub_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:paddingBottom="3dip"
android:textColor="#9b737775" android:textSize="14sp"
/>

</RelativeLayout>

RSSItem.java

package example.javatpoint.com.androidrssfeed;

public class RSSItem { public


String title; public String link;
public String description;
public String pubdate; public
String guid;
public RSSItem(String title, String link, String description, String pubdate, String guid)
{ this.title = title;
this.link
= link; this.description =
description; this.pubdate =
pubdate; this.guid
= guid;
}
}

RSSParser.java:

package example.javatpoint.com.androidrssfeed;

import android.util.Log; import


org.apache.http.HttpEntity; import
org.apache.http.HttpResponse; import
org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils; import
org.w3c.dom.Document; import
org.w3c.dom.Element; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import
org.xml.sax.InputSource; import
org.xml.sax.SAXException;

import java.io.IOException; import java.io.StringReader;


import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder; import


javax.xml.parsers.DocumentBuilderFactory; import
javax.xml.parsers.ParserConfigurationException;
public class RSSParser {

// RSS XML document CHANNEL tag private static


String TAG_CHANNEL = "channel"; private static
String TAG_TITLE = "title"; private static String
TAG_LINK = "link"; private static String
TAG_DESRIPTION = "description"; private static
String TAG_ITEM = "item"; private static String
TAG_PUB_DATE = "pubDate";
private static String TAG_GUID = "guid";

public RSSParser() {
}

public List<RSSItem> getRSSFeedItems(String rss_url) {


List<RSSItem> itemsList = new ArrayList<RSSItem>();
String rss_feed_xml;

rss_feed_xml = this.getXmlFromUrl(rss_url);
if (rss_feed_xml != null) { try {
Document doc = this.getDomElement(rss_feed_xml);
NodeList nodeList = doc.getElementsByTagName(TAG_CHANNEL);
Element e = (Element) nodeList.item(0);

NodeList items = e.getElementsByTagName(TAG_ITEM);


for (int i = 0; i < items.getLength(); i++) {
Element e1 = (Element) items.item(i);

String title = this.getValue(e1, TAG_TITLE);


String link = this.getValue(e1, TAG_LINK);
String description = this.getValue(e1, TAG_DESRIPTION);
String pubdate = this.getValue(e1, TAG_PUB_DATE);
String guid = this.getValue(e1, TAG_GUID);

RSSItem rssItem = new RSSItem(title, link, description, pubdate, guid);


// adding item to list itemsList.add(rssItem);
}
} catch (Exception e) { //
Check log for errors
e.printStackTrace();
}
}
return itemsList;
}

public String getXmlFromUrl(String url) {


String xml = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) { e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace(); } catch
(IOException e) {
e.printStackTrace();
}
return xml;
}

public Document getDomElement(String xml) {


Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml)); doc
= db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
return doc;
}

public final String getElementValue(Node elem) {


Node child; if (elem != null) { if
(elem.hasChildNodes()) {
for (child = elem.getFirstChild(); child != null; child = child
.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE || (child.getNodeType() ==
Node.CDATA_SECTION_NODE)) {
return child.getNodeValue();
}
}
}
} return
"";
}

public String getValue(Element item, String str) { NodeList


n = item.getElementsByTagName(str); return
this.getElementValue(n.item(0));
}
}

activity_rssfeed.xml:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/relativeLayout"
android:orientation="vertical">

<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
</RelativeLayout>

RSSFeedActivity.java:

package example.javatpoint.com.androidrssfeed;

import android.app.ListActivity;
import android.content.Intent; import
android.os.AsyncTask; import
android.os.Bundle; import
android.view.View; import
android.widget.AdapterView; import
android.widget.ListAdapter; import
android.widget.ListView; import
android.widget.ProgressBar; import
android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.text.ParseException; import


java.text.SimpleDateFormat; import
java.util.ArrayList; import java.util.Date;
import java.util.HashMap; import
java.util.List; import java.util.Locale;

public class RSSFeedActivity extends ListActivity {

private ProgressBar pDialog;


ArrayList<HashMap<String, String>> rssItemList = new ArrayList<>();
RSSParser rssParser = new RSSParser();
List<RSSItem> rssItems = new ArrayList<>();
private static String TAG_TITLE = "title"; private
static String TAG_LINK = "link"; private static
String TAG_PUB_DATE = "pubDate";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rssfeed);

String rss_link = getIntent().getStringExtra("rssLink");


new LoadRSSFeedItems().execute(rss_link);
ListView lv = getListView();

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent in = new Intent(getApplicationContext(), WebActivity.class);
String page_url = ((TextView)
view.findViewById(R.id.page_url)).getText().toString().trim();
in.putExtra("url", page_url);
startActivity(in);
}
});
}

public class LoadRSSFeedItems extends AsyncTask<String, String, String> {


@Override protected void
onPreExecute() {
super.onPreExecute();
pDialog = new ProgressBar(RSSFeedActivity.this, null,
android.R.attr.progressBarStyleLarge);
RelativeLayout relativeLayout = findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams layoutParams = new
RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);

layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
pDialog.setLayoutParams(layoutParams);
pDialog.setVisibility(View.VISIBLE);
relativeLayout.addView(pDialog);
}

@Override
protected String doInBackground(String... args) {
// rss link url
String rss_url = args[0];
// list of rss items
rssItems = rssParser.getRSSFeedItems(rss_url);
// looping through each item for
(final RSSItem item : rssItems) {
// creating new HashMap if
(item.link.toString().equals(""))
break; HashMap<String,
String> map = new HashMap<String,
String>();

// adding each child node to HashMap key => value


String givenDateString = item.pubdate.trim();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy
HH:mm:ss Z");
try {
Date mDate = sdf.parse(givenDateString);
SimpleDateFormat sdf2 = new SimpleDateFormat("EEEE, dd MMMM yyyy
- hh:mm a", Locale.US);
item.pubdate = sdf2.format(mDate);

} catch (ParseException e) { e.printStackTrace();


}

map.put(TAG_TITLE, item.title);
map.put(TAG_LINK, item.link);
map.put(TAG_PUB_DATE, item.pubdate);
// adding HashList to ArrayList
rssItemList.add(map);
}
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
RSSFeedActivity.this,
rssItemList, R.layout.rss_item_list_row,
new String[]{TAG_LINK, TAG_TITLE, TAG_PUB_DATE},
new int[]{R.id.page_url, R.id.title, R.id.pub_date});

// updating listview
setListAdapter(adapter);
}
});
return null;
}

protected void onPostExecute(String args) {


pDialog.setVisibility(View.GONE);
}
}
}

activity_web.xml:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:id="@+id/relativeLayout"
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</android.support.v4.widget.NestedScrollView>
</RelativeLayout> WebActivity.java
package example.javatpoint.com.androidrssfeed;

import android.content.Context;
import android.content.Intent; import
android.graphics.Bitmap; import
android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils; import
android.webkit.WebChromeClient; import
android.webkit.WebResourceError; import
android.webkit.WebResourceRequest;
import android.webkit.WebView; import
android.webkit.WebViewClient; import
android.widget.Toast;

public class WebActivity extends AppCompatActivity {

WebView webView;
String url;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web); Intent in = getIntent(); url =
in.getStringExtra("url"); if (TextUtils.isEmpty(url)) {
Toast.makeText(getApplicationContext(), "URL not found",
Toast.LENGTH_SHORT).show();
finish();
}
webView = findViewById(R.id.webView);
initWebView(); webView.loadUrl(url);
}

private void initWebView() {


webView.setWebChromeClient(new MyWebChromeClient(this));
webView.clearCache(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setHorizontalScrollBarEnabled(false);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request,
WebResourceError error) {
super.onReceivedError(view, request, error);
invalidateOptionsMenu();
}d
});
webView.clearCache(true); webView.clearHistory();
webView.getSettings().setJavaScriptEnabled(true);
webView.setHorizontalScrollBarEnabled(false);
}

private class MyWebChromeClient extends WebChromeClient {


Context context;
public MyWebChromeClient(Context context) { super();
this.context = context;
}
}
}
OUTPUT:

RESULT:

Thus to implement animation in Android Studio have been executed successfully.


Exp No : 13 Database Connection using Firebase Console

Date :

Aim :
To implement Database Connection using Firebase Console in Android Studio.

Algorithm :
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"
android:padding="16dp"
tools:context=".MainActivity">

<EditText
android:id="@+id/idEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Enter
ID" android:layout_marginBottom="8dp"/>

<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:layout_below="@id/idEditText"
android:layout_marginBottom="8dp"/>

<Button android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Add
Data" android:layout_below="@id/nameEditText"
android:layout_marginBottom="8dp"/>

<EditText
android:id="@+id/removeIdEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter ID to Remove"
android:layout_below="@id/addButton"
android:layout_marginBottom="8dp"/>

<Button android:id="@+id/removeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove Data"
android:layout_below="@id/removeIdEditText"
android:layout_marginBottom="8dp"/>

<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_below="@id/removeButton"/>

</RelativeLayout>

MainActivity.Java

package com.example.myguiapplication;

import android.content.ContentValues; import


android.database.Cursor; import
android.database.sqlite.SQLiteDatabase; import
android.os.Bundle; import android.view.View;
import android.widget.Button; import
android.widget.EditText; import
android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity { private EditText


idEditText; private EditText nameEditText; private
EditText removeIdEditText; private Button
addButton; private Button removeButton;
private TextView textView;

private DatabaseHelper dbHelper;

@Override protected void onCreate(Bundle


savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

idEditText = findViewById(R.id.idEditText); nameEditText =


findViewById(R.id.nameEditText); removeIdEditText =
findViewById(R.id.removeIdEditText); addButton =
findViewById(R.id.addButton); removeButton =
findViewById(R.id.removeButton); textView =
findViewById(R.id.textView);

dbHelper = new DatabaseHelper(this);


SQLiteDatabase db = dbHelper.getWritableDatabase();

addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = idEditText.getText().toString();
String name = nameEditText.getText().toString();

if (!id.isEmpty() && !name.isEmpty()) {


insertData(db, Integer.parseInt(id), name);
idEditText.setText("");
nameEditText.setText(""); // Refresh
data after insertion
refreshData(db);
}
}
});

removeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String removeId = removeIdEditText.getText().toString();

if (!removeId.isEmpty()) { removeData(db,
Integer.parseInt(removeId));
removeIdEditText.setText(""); //
Refresh data after removal
refreshData(db);
}
}
});

// Display initial data refreshData(db);


}

private void insertData(SQLiteDatabase db, int id, String name) {


ContentValues values = new ContentValues(); values.put("id", id);
values.put("name", name); db.insert("mytable", null, values);
}

private void removeData(SQLiteDatabase db, int id) {


db.delete("mytable", "id = ?", new String[]{String.valueOf(id)});
}

private void refreshData(SQLiteDatabase db) {


String data = readData(db); textView.setText(data);
}

private String readData(SQLiteDatabase db) {


StringBuilder result = new StringBuilder();
Cursor cursor = db.rawQuery("SELECT * FROM mytable", null); if
(cursor.moveToFirst()) { do {
int id = cursor.getInt(cursor.getColumnIndex("id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
result.append("ID: ").append(id).append(", Name:
").append(name).append("\n");
} while (cursor.moveToNext());
}
cursor.close();
return result.toString();
}}

DatabaseHelper.java

package com.example.myguiapplication;

import android.content.Context; import


android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "mydatabase";


private static final int DATABASE_VERSION = 1; private static
final String TABLE_NAME = "mytable"; private static final String
COLUMN_ID = "id"; private static final String COLUMN_NAME =
"name";

private static final String CREATE_TABLE = "CREATE


TABLE " + TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME + " TEXT)";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override public void onCreate(SQLiteDatabase


db) { db.execSQL(CREATE_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}}
Output :

Result :
Thus the program to implement database connection has been implemented
successfully
Exp No : 14 Project on Notes Application

Date :

Aim :
To create a Project on Notes Application in Android Studio.

Algorithm :
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">

<!--Adding a ListView -->

<ListView

android:id="@+id/listView" android:layout_width="409dp"

android:layout_height="601dp" android:layout_marginTop="80dp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" /> <!--Adding a TextView -->

<TextView

android:id="@+id/textView2" android:layout_width="0dp" android:layout_height="0dp"

android:gravity="center_horizontal" android:text="GFG"

android:textColor="@android:color/holo_green_dark" android:textSize="30sp"

app:layout_constraintBottom_toTopOf="@+id/listView"

app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Xml :

<?xml version="1.0" encoding="utf-8"?>

<!--Adding Menu to show the function to

User to delete and edit the data-->

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/add_note" android:title="Add note"></item>

</menu>

Xml :

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintla
yout.widget.Constraint
Layout
xmlns:android="http://
schemas.android.com
/apk/res/android"
xmlns:app="http://sch
emas.android.com/ap
k/resauto"
xmlns:tools="http://sc
hemas.android.com/to
ols"
android:layout_width=
"match_parent"
android:layout_height
="match_parent"
tools:context=".NoteE ditorActivity">

<!--Adding Edit Text


To add data to List View-->
<EditText

android:id="@+id/edit Text"

android:layout_width= "0dp"

android:layout_height
="0dp"
android:ems="10"
android:gravity="top|le
ft"

android:inputType="te xtMultiLine"

app:layout_constraint
Bottom_toBottomOf="
parent"

app:layout_constraint End_toEndOf="parent
"

app:layout_constraint Start_toStartOf="pare
nt"

app:layout_constraint
Top_toTopOf="parent
" /> </androidx.constraintl ayout.widget.Constrai ntLayout>

JAVA:

import android.content.Context; import

android.content.Intent; import

android.content.SharedPreferences; import

android.os.Bundle; import android.text.Editable;

import android.text.TextWatcher; import

android.widget.EditText; import
androidx.appcompat.app.AppCompatActivity;
import java.util.HashSet;

public class NoteEditorActivity extends AppCompatActivity {

int noteId;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState); setContentView(R.layout.activity_note_editor);

EditText editText = findViewById(R.id.editText);

// Fetch data that is passed from MainActivity

Intent intent = getIntent();

// Accessing the data using key and value noteId =

intent.getIntExtra("noteId", -1);

if (noteId != -1) {

editText.setText(MainActivity.notes.get(noteId));

} else {

MainActivity.notes.add(""); noteId = MainActivity.notes.size() - 1;

MainActivity.arrayAdapter.notifyDataSetChanged();

editText.addTextChangedListener(new TextWatcher() {

@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

// add your code here

@Override

public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

MainActivity.notes.set(noteId, String.valueOf(charSequence));

MainActivity.arrayAdapter.notifyDataSetChanged();

// Creating Object of SharedPreferences to store data in the phone

SharedPreferences sharedPreferences =
getApplicationContext().getSharedPreferences("com.example.notes", Context.MODE_PRIVATE);

HashSet<String> set = new HashSet(MainActivity.notes);

sharedPreferences.edit().putStringSet("notes", set).apply();

@Override

public void afterTextChanged(Editable editable) {

// add your code here

});

JAVA:

import android.content.Context; import

android.content.DialogInterface; import

android.content.Intent; import

android.content.SharedPreferences; import

android.os.Bundle; import android.view.Menu;


import android.view.MenuInflater; import

android.view.MenuItem; import android.view.View;

import android.widget.AdapterView; import

android.widget.ArrayAdapter; import

android.widget.ListView; import

androidx.annotation.NonNull; import

androidx.appcompat.app.AlertDialog; import

androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList; import

java.util.HashSet;

public class MainActivity extends AppCompatActivity {

static ArrayList<String> notes = new ArrayList<>(); static

ArrayAdapter arrayAdapter;

@Override

public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater menuInflater = getMenuInflater();


menuInflater.inflate(R.menu.add_note_menu, menu);

return super.onCreateOptionsMenu(menu);

@Override

public boolean onOptionsItemSelected(@NonNull MenuItem item) {

super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.add_note) {

// Going from MainActivity to NotesEditorActivity

Intent intent = new Intent(getApplicationContext(), NoteEditorActivity.class);

startActivity(intent); return true;

return false;

@Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ListView listView = findViewById(R.id.listView);

SharedPreferences sharedPreferences =
getApplicationContext().getSharedPreferences("com.example.notes", Context.MODE_PRIVATE);
HashSet<String> set = (HashSet<String>) sharedPreferences.getStringSet("notes", null);

if (set == null) {

notes.add("Example note");

} else {

notes = new ArrayList(set);

// Using custom listView Provided by Android Studio

arrayAdapter = new ArrayAdapter(this,


android.R.layout.simple_expandable_list_item_1, notes);
listView.setAdapter(arrayAdapter);

listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

// Going from MainActivity to NotesEditorActivity

Intent intent = new Intent(getApplicationContext(),


NoteEditorActivity.class);

intent.putExtra("noteId", i);

startActivity(intent);

});

listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

@Override

public boolean onItemLongClick(AdapterView<?> adapterView,


View view, int i, long l) {

final int itemToDelete = i; //

To delete the data from the App new

AlertDialog.Builder(MainActivity.this)

.setIcon(android.R.drawable.ic_dialog_alert)

.setTitle("Are you sure?")

.setMessage("Do you want to delete this note?")

.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {

@Override public void onClick(DialogInterface dialogInterface, int i) {

notes.remove(itemToDelete);

arrayAdapter.notifyDataSetChanged();

SharedPreferences
sharedPreferences = getApplicationContext().getSharedPreferences("com.example.notes",
Context.MODE_PRIVATE);

HashSet<String> set = new


HashSet(MainActivity.notes);

sharedPreferences.edit().putStringSet("notes",
set).apply();

}).setNegativeButton("No", null).show();

return true;

});

}
OUTPUT:

RESULT:

Thus the program to implement database connection has been implemented successfully.

You might also like