0% found this document useful (0 votes)
54 views24 pages

Android Applications

This document contains code for an Android student attendance management application. It includes Java code for activities like adding a student, viewing student details, and listing students. It also includes XML layout files and test files. The application allows adding student details like name, phone, email, division, and skills. It displays students in a list and shows individual student details.

Uploaded by

rohan p
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)
54 views24 pages

Android Applications

This document contains code for an Android student attendance management application. It includes Java code for activities like adding a student, viewing student details, and listing students. It also includes XML layout files and test files. The application allows adding student details like name, phone, email, division, and skills. It displays students in a list and shows individual student details.

Uploaded by

rohan p
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/ 24

MGM’s College of Engineering,

Nanded
Department of Electronics and
Telecommunication

SUBJECT : Android Programming

Project name :- 1)Student Attendance Management


2)Flashlight

Team member:-I)Yannawar Vyankatesh (Roll No. 65)


II)Pawar Rohan (Roll No.78)
Student attendance management application

JAVA Programmes
AddStudentActivity.java
package com.example.user.studentmanagement;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;

public class AddStudentActivity extends AppCompatActivity {


EditText nameET, phoneET, emailET, dobET;
Spinner divisionSP;
RadioGroup genderRG;
String division, gender;

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

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_student);
nameET = findViewById(R.id.nameET);
phoneET = findViewById(R.id.phoneET);
emailET = findViewById(R.id.emailET);
dobET = findViewById(R.id.dobET);
divisionSP = findViewById(R.id.divisionSP);
genderRG = findViewById(R.id.genderRG);

final String divisionList[] = {"E&TC", "IT", "CSE", "MECH",


"CIVIL"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_dropdown_item,
divisionList);
divisionSP.setAdapter(adapter);

divisionSP.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View
view, int position, long id) {
division = divisionList[position];
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});

genderRG.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int
checkedId) {
RadioButton genderRB = findViewById(checkedId);
gender = genderRB.getText().toString();
}

});
}

public void submitStudent(View view) {


String name = nameET.getText().toString();
String phone = phoneET.getText().toString();
String email = emailET.getText().toString();
String dob = dobET.getText().toString();

Student student = new Student(name, phone, email, dob,


division, gender, skillList);
Student.addStudentIntheList(student);

Toast.makeText(this, "Data Added Successfully!",


Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, StudentListActivity.class);
startActivity(intent);

}
Student.java
package com.example.user.studentmanagement;

import java.io.Serializable;
import java.util.ArrayList;

public class Student implements Serializable {


private String name, phone, email, dob, division, gender;

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

private static ArrayList<Student> studentList = new


ArrayList<Student>();

public Student(String name, String phone, String email, String


dob, String division, String gender, ArrayList<String> skillList) {
this.name = name;
this.phone = phone;
this.email = email;
this.dob = dob;
this.division = division;
this.gender = gender;
this.skillList = skillList;
}

public String getName() {


return name;
}

public String getPhone() {


return phone;
}

public String getEmail() {


return email;
}

public String getDob() {


return dob;
}

public String getDivision() {


return division;
}

public String getGender() {


return gender;
}

public ArrayList<String> getSkillList() {


return skillList;
}
public static void addStudentIntheList(Student student){
studentList.add(student);
}

public static ArrayList<Student> getStudentList() {


return studentList;
}
}
StudentDetailsActivity.java

package com.example.user.studentmanagement;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class StudentDetailsActivity extends AppCompatActivity {

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

Intent intent = getIntent();


Student student = (Student)
intent.getSerializableExtra("student");

Log.d("name", student.getName());
Log.d("phone", student.getPhone());
Log.d("email", student.getEmail());
Log.d("dob", student.getDob());
Log.d("division", student.getDivision());
Log.d("gender", student.getGender());

}
}
StudentListActivity.java
package com.example.user.studentmanagement;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class StudentListActivity extends AppCompatActivity {


ListView studentLV;

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

studentLV = findViewById(R.id.studentListLV);

ArrayList<Student> studentList = Student.getStudentList();

StudentListAdapter adapter = new StudentListAdapter(this,


studentList);

studentLV.setAdapter(adapter);

studentLV.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View
view, int position, long id) {
Student student =
Student.getStudentList().get(position);
Intent intent = new Intent(StudentListActivity.this,
StudentDetailsActivity.class);
intent.putExtra("student", student);
startActivity(intent);

}
});

public void addStudent(View view) {


Intent intent = new Intent(this, AddStudentActivity.class);
startActivity(intent);
}
}
StudentAdapterActivity.java

package com.example.user.studentmanagement;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class StudentListAdapter extends ArrayAdapter {


private ArrayList<Student> studentList;
private Context context;

public StudentListAdapter(@NonNull Context context,


ArrayList<Student> studentList) {
super(context, R.layout.student_list_adapter, studentList);

this.studentList = studentList;
this.context = context;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView,
@NonNull ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView =
inflater.inflate(R.layout.student_list_adapter, parent, false);

TextView nameTV = convertView.findViewById(R.id.nameTV);


TextView emailTV = convertView.findViewById(R.id.emailTV);

nameTV.setText(studentList.get(position).getName());
emailTV.setText(studentList.get(position).getEmail());

return convertView;
}
}
ExamplesInstrumentedTest.java

package com.example.user.studentmanagement;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing
documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext =
InstrumentationRegistry.getTargetContext();

assertEquals("com.example.user.studentmanagement",
appContext.getPackageName());
}
}
ExampleUnitTest.java

package com.example.user.studentmanagement;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development
machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing
documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
XML FILES CODE
Activity_add_student.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"
tools:context=".AddStudentActivity">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/enter_your_name"
android:id="@+id/nameET"
android:inputType="text"
android:autofillHints="" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/enter_your_phone"
android:id="@+id/phoneET"
android:inputType="number"
android:autofillHints="" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/enter_your_email"
android:id="@+id/emailET"
android:inputType="textEmailAddress"
android:autofillHints="" />

<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:text="@string/branch"

android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
/>

<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/divisionSP"
></Spinner>
</LinearLayout>

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/genderRG"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/male"
android:id="@+id/maleRB"
/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/female"
android:id="@+id/femaleRB"
/>

</RadioGroup>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/date_of_birth"
android:id="@+id/dobET"
android:inputType="TODO"
android:autofillHints="" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/submit"
android:onClick="submitStudent"
/>

</LinearLayout>
Activity_student_details.xml

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


<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StudentDetailsActivity">

</android.support.constraint.ConstraintLayout>
Activity_studentlist.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=".StudentListActivity">

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/studentListLV"
></ListView>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_student"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:onClick="addStudent"
/>
</RelativeLayout>
student_list_adapter.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"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nameTV"
android:text="@string/name"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/emailTV"
android:text="@string/email"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
Flashlight android application
MainActivity.java

public class MainActivity extends AppCompatActivity {


ImageButton imageButton;
Camera camera;
Camera.Parameters parameters;
Boolean isflash = false;
Boolean ison = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton = (ImageButton) findViewById(R.id.imageButton);
if
(getApplicationContext().getPackageManager().hasSystemFeature(Packag
eManager.FEATURE_CAMERA_FLASH))
;

{
camera = camera.open();
parameters = camera.getParameters();
isflash = true;
}
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

if (isflash) {
if (!ison) {
imageButton.setImageResource(R.drawable.on);

parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
camera.startPreview();
ison = true;
} else {

imageButton.setImageResource(R.drawable.off);

parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
camera.setParameters(parameters);
camera.stopPreview();
ison = false;
}
} else {
AlertDialog.Builder builder = new
AlertDialog.Builder(MainActivity.this);
builder.setTitle("Error........");
builder.setMessage("Flashlight is not available
on your device");
builder.setPositiveButton("ok", new
DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface


dialogInterface, int i) {

dialogInterface.dismiss();
finish();
}
});

AlertDialog alertDialog = builder.create();


alertDialog.show();

}
}
});
}

@Override
protected void onStop() {
super.onStop();
if (camera!=null)
{
camera.release();
camera=null;
}
}
}
XML CODE
Activity_main.xml

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="@string/TextView"
android:textSize="38sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

<ImageButton
android:id="@+id/imageButton"
android:layout_width="377dp"
android:layout_height="503dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="false"

android:contentDescription="@android:string/defaultMsisdnAlphaTag"
android:src="@drawable/off"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.516"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>

You might also like