mad exp 8 and 10
mad exp 8 and 10
mad exp 8 and 10
Procedure:
Step 1: Form design
1. Create new project.
4. Create a New EmptyActivity from right click on the java folder and name it as
“HomeActivity”.
Step 2: Open java -> MainActivity.java and write the code needed for splash screen.
Step 3: Run the program using following steps in Android Emulator.
Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.
Program:
Design View code file name: 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/instragram"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
Splashscreen page activity code : HomeActivity.java
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="InstragramApp"
android:textColor="@color/black"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.splash;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
@Override
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
@Override
startActivity(Intent);
finish();
}, SPLASH_TIMER);
return insets;
});
Output:
Result:
Thus, the splash screen was developed using Android studio and the output was
verified.
Ex.No.9 Develop an Android Application that uses layout managers and Event
listeners
Date:
Aim:
To develop an android application that uses layout managers and Event listeners
Procedure:
Step 1: Form design
1. Create new project.
3. Create different layout managers and add the View elements in the xml code
4. Add the necessary properties in the xml code for the Layouts and View Elements in
the MainActivity.xml
Step 2: Open java -> MainActivity.java and write the code needed for splash screen.
Step 3: Run the program using following steps in Android Emulator.
Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.
Program:
Design View code file name: activity main.xml
<?xml version="1.0" encoding="utf-8"?>
<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">
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<EditText
android:id="@+id/editTextReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Registration Number" />
<EditText
android:id="@+id/editTextDept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Department" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
package com.example.layout;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
editTextReg=findViewById(R.id.editTextReg);
editTextDept=findViewById(R.id.editTextDept);
buttonSubmit=findViewById(R.id.buttonSubmit);
buttonSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = editTextName.getText().toString();
String reg = editTextReg.getText().toString();
String dept = editTextDept.getText().toString();
if (!name.isEmpty() && !reg.isEmpty() && !dept.isEmpty()) {
Toast.makeText(MainActivity.this, "Submitted:\nName: " + name +
"\nReg: " + reg + "\nDept: " + dept, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Please fill all fields",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output:
Result:
Thus, uses layout managers and event listeners was developed using Android studio and the
output was verified.
Date:
Aim:
To develop an android application that to Create alarm clock.
Procedure:
Step 1: Form design
1. Create new project.
3. Create different layout managers and add the View elements in the xml code
4. Add the necessary properties in the xml code for the Layouts and View Elements in
the MainActivity.xml
Step 2: Open java -> MainActivity.java and write the code needed for splash screen.
Step 3: Run the program using following steps in Android Emulator.
Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.
Program:
Design View code file name: 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"
tools:context=".MainActivity" >
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alarm On/Off"
android:id="@+id/alarmToggle"
android:layout_centerHorizontal="true"
android:layout_below="@+id/alarmTimePicker"
android:onClick="onToggleClicked" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/alarmText"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="@+id/alarmToggle" />
<TimePicker
android:id="@+id/alarmTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp" />
</RelativeLayout>
package com.example.alarmclock;
import java.util.Calendar;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.ToggleButton;
AlarmManager alarmManager;
return inst;
@Override
super.onStart();
inst = this;
@Override
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (((ToggleButton) view).isChecked()) {
.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,
alarmTimePicker
.getCurrentHour());
calendar.set(Calendar.MINUTE,
alarmTimePicker
.getCurrentMinute());
MainActivity.this,
AlarmReceiver.class);
pendingIntent = PendingIntent
.getBroadcast(
MainActivity.this, 0,
myIntent, 0);
alarmManager.set(AlarmManager.RTC,
calendar.getTimeInMillis(),
pendingIntent);
} else {
alarmManager.cancel(pendingIntent);
setAlarmText("");
alarmTextView.setText(alarmText);
package com.example.alarmclock;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.util.Log;
public class AlarmReceiver extends BroadcastReceiver {
private MediaPlayer mediaPlayer;
@Override
public void onReceive(final Context context, Intent intent) { Log.d("AlarmReceiver", "Alarm received!");
MainActivity inst = MainActivity.instance();
if (inst != null) {
inst.setAlarmText("Wake Up... It is a bright day ahead!..");
}
playAlarmSound(cont
Intent serviceIntent = new Intent(context, com.example.alarmclock.AlarmService.class);
context.startForegroundService(serviceIntent);
setResultCode(Activity.RESULT_OK);
}
private void playAlarmSound(Context context) {
try {
Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmUri == null) {
alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(context, alarmUri);
mediaPlayer.setLooping(true); // Keep alarm looping
mediaPlayer.prepare();
mediaPlayer.start();
Log.d("AlarmReceiver", "Alarm sound is playing.");
} catch (Exception e) {
Log.e("AlarmReceiver", "Error playing alarm sound", e);
}
}
public void stopAlarmSound() {
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
Log.d("AlarmReceiver", "Alarm sound stopped.");
}
}
}
package com.example.alarmclock;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import androidx.core.app.NotificationCompat;
@Override
public IBinder onBind(Intent intent) {
// This service does not support binding.
return null;
}
}
Output:
Result:
Thus, to Create Alarm Clock was developed using Android studio and the output was verified