You are on page 1of 10

Android App for Teachers with Source Code

By GenuineCoder - April 27, 2016

Todayiamgoingtodevelopanandroidapplicaonforteachers.Androidistheidealplaormfor
developingsuchanapplicaonduetothewidevarietyofdevicesitsupports.ThisAndroidapp
forteacherssupportbasicfunconaliessuchasaddingstudenttoeachclass/department,save
notes,makeschedulesforclassesetc.ItalsoprovidesaCGPAcalculatorthatbasicallycalculate
CGPAfromthegivengradepoints.

The First Acvity Contains a Grid view that


providestheconnecontobasicacvies.The
Aendancemoduleisaddedtotakeaendance
and store it in a database. The scheduler is
basicallyusedtoscheduleaparculareventso
that teachers wont be needing another
applicaonasreminder.
Notes provides an easier way to save notes
easilyandquickly.Notescanalsobeassociated
withasubjectsothatitwillbepoppedupwhen
theteachertakesattendanceforthatsubject.
ProfileModuleprovidessupporttoviewandedit
student data, along with activity to add new
students.
FeaturesAvailable

Takeaendanceandkeepthemclasswise
Add New student. View each students
aendanceseperately
EditStudent/Aendancelater
Savenotessubjectwise
Automac nocaon about notes availble
whentheteachertakesaendance
Scheduleclasses
CGPAcalculator
SimpleandMaterialdesignedinteface

TheDatabase

Simple mysqli database is used to store data
throughdierenttables.
databaseHandler.java
importandroid.app.Activity;
importandroid.database.Cursor;
importandroid.database.sqlite.SQLiteDatabase;
importandroid.util.Log;
importandroid.widget.Toast;
publicclassdatabaseHandler{
SQLiteDatabasedatabase;
Activityactivity;
publicdatabaseHandler(Activityactivity){
this.activity=activity;
database=activity.openOrCreateDatabase("ASSIST",activity.MODE_PRIVATE,null);
createTable();
}
publicvoidcreateTable()
{
try{
Stringqu="CREATETABLEIFNOTEXISTSSTUDENT(namevarchar(1000),"+
"clvarchar(100),"+
"regnovarchar(100)primarykey,contactvarchar(100),rollinteger);";
database.execSQL(qu);
}catch(Exceptione)
{
Toast.makeText(activity,"ErrorOccuredforcreatetable",Toast.LENGTH_LONG).show();
}
try{
Stringqu="CREATETABLEIFNOTEXISTSATTENDANCE(datexdate,"+
"hourint,"+
"registervarchar(100),isPresentboolean);";
database.execSQL(qu);
}catch(Exceptione)
{
Toast.makeText(activity,"ErrorOccuredforcreatetable",Toast.LENGTH_LONG).show();
}
try{
Stringqu="CREATETABLEIFNOTEXISTSNOTES(titlevarchar(100)notnull,"+
"bodyvarchar(10000),clsvarchar(1000),subvarchar(1000),datexTIMESTAMPdefaultCURRENT_TIMESTAMP);";
database.execSQL(qu);
}catch(Exceptione)
{
Toast.makeText(activity,"ErrorOccuredforcreatetable",Toast.LENGTH_LONG).show();
}
try{
Stringqu="CREATETABLEIFNOTEXISTSSCHEDULE(clvarchar(100),subjectvarchar(1000),"+
"timextime,day_weekvarchar(100));";
database.execSQL(qu);
}catch(Exceptione)
{
Toast.makeText(activity,"ErrorOccuredforcreatetable",Toast.LENGTH_LONG).show();
}
}
publicbooleanexecAction(Stringqu)
{
Log.i("databaseHandler",qu);
try{
database.execSQL(qu);
}catch(Exceptione)
{
Log.e("databaseHandler",qu);
Toast.makeText(activity,"ErrorOccuredforexecAction",Toast.LENGTH_LONG).show();
returnfalse;
}
returntrue;
}
CursorexecQuery(Stringqu)
{
try{
returndatabase.rawQuery(qu,null);
}catch(Exceptione)
{
Log.e("databaseHandler",qu);
//Toast.makeText(activity,"ErrorOccuredforexecAction",Toast.LENGTH_LONG).show();
}
returnnull;
}
}

database=activity.openOrCreateDatabase("ASSIST",activity.MODE_PRIVATE,null);

The code is used to create or open the database in private mode. Aer opening the mysqli
databaseallnormalmysqloperaonscanbeperformedonthedatabase.

I always prefer execung custom sql queries. So I have made 2 funcons called execQuery and
execAcon. The execAcon uses execSql funcon to execute INSERT, DELETE OR UPDATE
operaons on the database. execAcon returns a cursor which can be used to get the rows
returnedfromSELECTquery.
TheFirstAcvity:AppBase.java
Asdenotedearlier,therstacvitycontainsAndroidGridLayoutwhichhelpstheusertoeasily
ndthecontenttheyarelookingfor.ThefollowingcodeisthelayoutXMLforAppBaseAcvity.

<?xmlversion="1.0"encoding="utf8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
>
<GridView
android:layout_width="match_parent"
android:numColumns="2"
android:id="@+id/grid"
android:background="#e7e7e7"
android:columnWidth="150dp"
android:gravity="center"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:layout_height="match_parent">
</GridView>
</LinearLayout>

TheGridLayouthasbothwidthandheightandMatchParentsothatitwilltintothewhole
screen.

BaseAcvity.java
Nowletsunderstandthecodefortherstacvity.

importandroid.app.Activity;
importandroid.content.Intent;
importandroid.database.Cursor;
importandroid.database.sqlite.SQLiteDatabase;
importandroid.support.design.widget.FloatingActionButton;
importandroid.support.design.widget.Snackbar;
importandroid.support.v7.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.util.Log;
importandroid.view.Menu;
importandroid.view.MenuInflater;
importandroid.view.MenuItem;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.GridView;
importjava.util.ArrayList;
publicclassAppBaseextendsAppCompatActivity{
ArrayList<String>basicFields;
gridAdapteradapter;
publicstaticArrayList<String>divisions;
GridViewgridView;
publicstaticdatabaseHandlerhandler;
publicstaticActivityactivity;
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
super.onCreateOptionsMenu(menu);
MenuInflaterinflater=getMenuInflater();
inflater.inflate(R.menu.mai_menu,menu);
returntrue;
}
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.base_layout);
basicFields=newArrayList<>();
handler=newdatabaseHandler(this);
activity=this;
getSupportActionBar().show();
divisions=newArrayList();
divisions.add("S1COMPUTERSCIENCE");
divisions.add("S2COMPUTERSCIENCE");
divisions.add("S3COMPUTERSCIENCE");
divisions.add("S4COMPUTERSCIENCE");
divisions.add("S5COMPUTERSCIENCE");
divisions.add("S6COMPUTERSCIENCE");
divisions.add("S7COMPUTERSCIENCE");
gridView=(GridView)findViewById(R.id.grid);
basicFields.add("ATTENDANCE");
basicFields.add("SCHEDULER");
basicFields.add("NOTES");
basicFields.add("PROFILE");
basicFields.add("CGPACALCULATOR");
adapter=newgridAdapter(this,basicFields);
gridView.setAdapter(adapter);
}
publicvoidloadSettings(MenuItemitem){
IntentlaunchIntent=newIntent(this,SettingsActivity.class);
startActivity(launchIntent);
}
publicvoidloadAbout(MenuItemitem){
IntentlaunchIntent=newIntent(this,About.class);
startActivity(launchIntent);
}
}

FromtheonCreate()method,wehaveinflatedthexmllayout.Thedatabasehandlerisdefinedas
apublicstaticvariablesothatitcanbeaccessedfromallotheractivitieswithouttheneedof
declarationandinitialization.IhaveusedacustomadapterforthegridviewcalledgridAdapter.

adapter=newgridAdapter(this,basicFields);

ThegridAdaptershouldgettheimagesandlistoftletoshowthegridview.Here,Ihavepassed
theArrayListbasicFieldsasheaderandtheimagesareloadedfromtheadapteritself.

gridView.setAdapter(adapter);

Thiswillsettheadapterastheadapterforgridview.
NowLetsconsidertheCustomGridAdapter

Custom Grid Adapter


gridAdapter.java

importandroid.app.Activity;
importandroid.app.AlertDialog;
importandroid.app.Dialog;
importandroid.app.DialogFragment;
importandroid.app.FragmentManager;
importandroid.app.Notification;
importandroid.app.NotificationManager;
importandroid.app.PendingIntent;
importandroid.content.DialogInterface;
importandroid.content.Intent;
importandroid.content.SharedPreferences;
importandroid.database.Cursor;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.preference.PreferenceManager;
importandroid.provider.Settings;
importandroid.support.v4.app.NotificationCompat;
importandroid.util.Log;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.view.animation.Animation;
importandroid.view.animation.ScaleAnimation;
importandroid.widget.ArrayAdapter;
importandroid.widget.BaseAdapter;
importandroid.widget.DatePicker;
importandroid.widget.EditText;
importandroid.widget.ImageView;
importandroid.widget.Spinner;
importandroid.widget.TextView;
importandroid.widget.Toast;
importjava.util.ArrayList;
importjava.util.StringTokenizer;
publicclassgridAdapterextendsBaseAdapter{
ArrayListnames;
publicstaticActivityactivity;
publicgridAdapter(Activityactivity,ArrayListnames){
this.activity=activity;
this.names=names;
}
@Override
publicintgetCount(){
returnnames.size();
}
@Override
publicObjectgetItem(intposition){
returnnames.get(position);
}
@Override
publiclonggetItemId(intposition){
returnposition;
}
@Override
publicViewgetView(intposition,Viewv,ViewGroupparent){
if(v==null){
LayoutInflatervi=LayoutInflater.from(activity);
v=vi.inflate(R.layout.grid_layout,null);
}
TextViewtextView=(TextView)v.findViewById(R.id.namePlacer);
ImageViewimageView=(ImageView)v.findViewById(R.id.imageHolder);
if(names.get(position).toString().equals("ATTENDANCE"))
{
imageView.setImageResource(R.drawable.ic_attendance);
v.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
FragmentManagerfm=activity.getFragmentManager();
createRequestrequest=newcreateRequest();
request.show(fm,"Select");
}
});
}elseif(names.get(position).toString().equals("SCHEDULER"))
{
imageView.setImageResource(R.drawable.ic_schedule);
v.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
IntentlaunchinIntent=newIntent(activity,scheduler.class);
activity.startActivity(launchinIntent);
}
});
}elseif(names.get(position).toString().equals("NOTES"))
{
imageView.setImageResource(R.drawable.ic_notes);
v.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
IntentlaunchinIntent=newIntent(activity,noteActivity.class);
activity.startActivity(launchinIntent);
}
});
}elseif(names.get(position).toString().equals("PROFILE"))
{
imageView.setImageResource(R.drawable.ic_profile);
v.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
IntentlaunchinIntent=newIntent(activity,profile_activity.class);
activity.startActivity(launchinIntent);
}
});
}
elseif(names.get(position).toString().equals("CGPACALCULATOR"))
{
imageView.setImageResource(R.drawable.ic_cgpa);
v.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
IntentlaunchinIntent=newIntent(activity,cgpa_activity.class);
activity.startActivity(launchinIntent);
}
});
}
textView.setText(names.get(position).toString());
returnv;
}
publicstaticclasscreateRequestextendsDialogFragment{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
}
@Override
publicDialogonCreateDialog(BundlesavedInstanceState){
AlertDialog.Builderbuilder=newAlertDialog.Builder(getActivity());
//Getthelayoutinflater
LayoutInflaterinflater=getActivity().getLayoutInflater();
finalViewv=inflater.inflate(R.layout.pick_period,null);
finalDatePickerdatePicker=(DatePicker)v.findViewById(R.id.datePicker);
finalEditTexthour=(EditText)v.findViewById(R.id.periodID);
finalSpinnerspn=(Spinner)v.findViewById(R.id.spinnerSubject);
Stringqu="SELECTDISTINCTsubFROMNOTES";
ArrayList<String>subs=newArrayList<>();
subs.add("NotSpecified");
Cursorcr=AppBase.handler.execQuery(qu);
if(cr!=null)
{
cr.moveToFirst();
while(!cr.isAfterLast()){
subs.add(cr.getString(0));
Log.d("gridAdapter.class","Cached"+cr.getString(0));
cr.moveToNext();
}
}else
Log.d("gridAdapter.class","NoSUBS"+cr.getString(0));
ArrayAdapter<String>adapterSpinner=newArrayAdapter<String>(activity,android.R.layout.simple_spinner_dropdown_item,subs);
assertspn!=null;
spn.setAdapter(adapterSpinner);
builder.setView(v)
//Addactionbuttons
.setPositiveButton("Enter",newDialogInterface.OnClickListener(){
@Override
publicvoidonClick(DialogInterfacedialog,intid){
intday=datePicker.getDayOfMonth();
intmonth=datePicker.getMonth()+1;
intyear=datePicker.getYear();
Stringdate=year+""+month+""+day;
Stringsubject=spn.getSelectedItem().toString();
Stringqx="SELECTtitleFROMNOTESwheresub='"+subject+"'";
Cursorcr=AppBase.handler.execQuery(qx);
Stringsubnames="";
if(cr!=null)
{
cr.moveToFirst();
while(!cr.isAfterLast()){
subnames+=(cr.getString(0))+"n";
cr.moveToNext();
}
}
makeNotification(subnames);
Cursorcursor=AppBase.handler.execQuery("SELECT*FROMATTENDANCEWHEREdatex='"+
date+"'ANDhour="+hour.getText()+";");
if(cursor==null||cursor.getCount()==0)
{
IntentlaunchinIntent=newIntent(AppBase.activity,attendanceActivity.class);
launchinIntent.putExtra("DATE",date);
launchinIntent.putExtra("PERIOD",hour.getText().toString());
AppBase.activity.startActivity(launchinIntent);
}else{
Toast.makeText(getActivity(),"PeriodAlreadyAdded",Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton("Cancel",newDialogInterface.OnClickListener(){
publicvoidonClick(DialogInterfacedialog,intid){
dialog.dismiss();
}
});
returnbuilder.create();
}
}
publicstaticvoidmakeNotification(StringuserIntrouble){
Log.d("NOTIFICATION","Building..........");
IntentnotificationIntent=newIntent(activity.getApplicationContext(),noteActivity.class);
PendingIntentpIntent=PendingIntent.getActivity(activity,0,notificationIntent,
0);
SharedPreferencessharedPrefs=PreferenceManager.getDefaultSharedPreferences(activity.getBaseContext());
Uriring=Uri.parse(sharedPrefs.getString("Notification_Sound",Settings.System.DEFAULT_RINGTONE_URI.toString()));
NotificationCompat.Builderbuilder=newNotificationCompat.Builder(activity.getBaseContext())
.setTicker("TickerTitle").setContentTitle("NotesAreAvailableForthissubject")
.setSmallIcon(R.drawable.ic_notes)
.setStyle(newNotificationCompat.BigTextStyle().bigText(userIntrouble))
.setContentIntent(pIntent)
.setSound(ring);
Notificationnoti=builder.build();
noti.contentIntent=pIntent;
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManagernotificationManager=(NotificationManager)activity.getSystemService(activity.NOTIFICATION_SERVICE);
notificationManager.notify(0,noti);
}
}

ThecustomadaptergridAdapterextendsAndroidsBaseAdapterandimplementsitsmethods.In
thegetViewmethod,wehaveinflatedboththetitleandImageViewusinganifelsecase.

Attendance Activity Create Dialog

AttendanceActivityDialog

ThecreaterequestdialogiscreatedwhentheuserclicksonAttendanceviewintheGridLayout.
AnonClickListenerisaddedfortheviewvintheabovecode.
Thedialogtakesthedateandhour(period)alongwithsubjectwhichistobetakenbytheteacher.
A notification module is added which will notify the teacher about the notes available for that
particularsubjectoncetheyclickontheEnteroption.MoreoverclickingtheEnterwilllaunchnew
ActivitycalledAttendanceActivity.

IntentlaunchinIntent=newIntent(AppBase.activity,attendanceActivity.class);
launchinIntent.putExtra("DATE",date);
launchinIntent.putExtra("PERIOD",hour.getText().toString());
AppBase.activity.startActivity(launchinIntent);

Inordertostarttheattendanceactivity,DATEandPERIODdataispassedthroughtheintent.Itis
thenaccessedfromthesecondactivityandprocessed.

Settings Activity

pref_general.xml

<PreferenceScreenxmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:title="ClearScheduledata"
android:summary="Clearallschedules"
android:key="clear_schedule"/>
<Preference
android:title="ClearAttendancedata"
android:summary="ClearallAttendanceData"
android:key="clear_attendance"/>
<Preference
android:title="ClearNotesdata"
android:summary="ClearallNotesData"
android:key="clear_notes"/>
<Preference
android:title="ClearStudentdata"
android:summary="ClearallStudentData"
android:key="clear_student"/>
</PreferenceScreen>
SettingsActivity

Inthesettings,Ihaveaddedoptionstoclearallthedatabases.TheabovecodeistheXMLlayout
forthepreferences.ThexmlisinflatedbySettingsActivity.javausing

addPreferencesFromResource(R.xml.pref_general)

Thenforeachpreferenceentryeventhandlerisprovidedusingthecode.

PreferencemyPref=findPreference("clear_schedule");
myPref.setOnPreferenceClickListener(newPreference.OnPreferenceClickListener(){
publicbooleanonPreferenceClick(Preferencepreference){
//DOACTIONHERE
}

So,thatsallabouttherstacvityofSAssistant,Androidappforteachers.Therearemanyother
modulesintheprogram.Ifeelitisnotagoodideatoexplainthemall.Ifyouwanttoexplainit,
pleaseletmeknowitonthecommentsecon.
Screenshots:

AddNewStudenttodatabase
CreateNewNote

MakeNewScheduleActivity
Listofnotes

DOWNLOADANDROIDAPPFORTEACHERSSOURCECODE

Anonymous
Whichapiisusedinthisapp?

cybernet
couldyoucreatean.apkfileplease.Iwouldliketouseitonmymobile

Anonymous
canyouexplainabitmoreabouthowyouconnectedyourdatabaseplease.Iamtryingtomakeanapp
withwebhostingandhowtousetheSQLdatabase.
thanks

Muhammad zubair
canyoumakeatutorialslikeyouhavecreatedinjavaFXlibrarymanagementsystem

Reginald Sabeta
canyoupleasegivemethephpcodes

Wahyu Artadianto
Error:(1,0)Pluginwithidcom.android.applicationnotfound.


HiCanyoupleasesharePHPcodes

You might also like