Android Applications
Android Applications
Nanded
Department of Electronics and
Telecommunication
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;
@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);
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();
}
});
}
}
Student.java
package com.example.user.studentmanagement;
import java.io.Serializable;
import java.util.ArrayList;
package com.example.user.studentmanagement;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_details);
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_studentlist);
studentLV = findViewById(R.id.studentListLV);
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);
}
});
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;
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);
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;
/**
* 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;
/**
* 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
<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
</android.support.constraint.ConstraintLayout>
Activity_studentlist.xml
<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
<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
@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
dialogInterface.dismiss();
finish();
}
});
}
}
});
}
@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>