parent communication register android application coding
TRANSCRIPT
AddFaculty.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;import android.app.ProgressDialog;import android.content.Intent;import android.os.AsyncTask;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;import android.widget.EditText;
import org.apache.http.NameValuePair;import org.apache.http.message.BasicNameValuePair;import org.json.JSONObject;
import java.util.ArrayList;import java.util.List;
public class Addfaculty extends Activity {
EditText fname, fmobile, femail,fdepart, fusername, fpassword; Button fadd; String nameString, mobileString, mailString, departString, usernameString, passwordString;
ProgressDialog progressDialog; JSONParser parser = new JSONParser();
public String addUrl = "http://www.wikihands.com/attendanceandmarks/facultyregister.php";
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_addfaculty);
fname = (EditText) findViewById(R.id.facultyname); fmobile = (EditText) findViewById(R.id.facultymobile); femail = (EditText) findViewById(R.id.facultymail); fdepart= (EditText) findViewById(R.id.facultydepart); fusername = (EditText) findViewById(R.id.ftusername); fpassword = (EditText) findViewById(R.id.ftpassword);
fadd = (Button) findViewById(R.id.addfaculty); fadd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
nameString=fname.getText().toString(); mobileString=fmobile.getText().toString(); mailString=femail.getText().toString(); departString=fdepart.getText().toString(); usernameString=fusername.getText().toString(); passwordString=fpassword.getText().toString();
new facultyadding().execute(); } }); }
public class facultyadding extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(Addfaculty.this); progressDialog.setMessage("Please wait......"); progressDialog.setCanceledOnTouchOutside(false); progressDialog.show(); }
@Override protected String doInBackground(String... params) {
try { List<NameValuePair> args = new ArrayList<>(); args.add(new BasicNameValuePair("name",nameString)); args.add(new BasicNameValuePair("phone",mobileString)); args.add(new BasicNameValuePair("mail",mailString)); args.add(new BasicNameValuePair("department",departString)); args.add(new BasicNameValuePair("username",usernameString)); args.add(new BasicNameValuePair("password",passwordString));
JSONObject jsonObject = parser.makeHttpRequest(addUrl, "POST", args);
} catch (Exception e) {
} return null; }
@Override
protected void onPostExecute(String s) { super.onPostExecute(s); progressDialog.dismiss();
Intent in = new Intent(Addfaculty.this, FacultyList.class); startActivity(in); } }
}
AddStudents.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;import android.app.ProgressDialog;import android.content.Intent;import android.os.AsyncTask;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;import android.widget.EditText;
import org.apache.http.NameValuePair;import org.apache.http.message.BasicNameValuePair;import org.json.JSONObject;
import java.util.ArrayList;import java.util.List;
public class Addstudent extends Activity {
EditText srollnumber,sname,smobile,semail,spassword; Button sadd;
String rollString,nameString,mobileString,mailString,passwordString;
ProgressDialog progressDialog; JSONParser parser = new JSONParser();
public String addUrl = "http://www.wikihands.com/attendanceandmarks/studentregister.php"; @Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_addstudent);
srollnumber= (EditText) findViewById(R.id.studentrollno); sname= (EditText) findViewById(R.id.studentname); smobile= (EditText) findViewById(R.id.studentmobile); semail= (EditText) findViewById(R.id.studentmail); spassword= (EditText) findViewById(R.id.stpassword);
sadd= (Button) findViewById(R.id.submit); sadd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
rollString=srollnumber.getText().toString(); nameString=sname.getText().toString(); mobileString=smobile.getText().toString(); mailString=semail.getText().toString(); passwordString=spassword.getText().toString();
new studentadding().execute(); } }); }
public class studentadding extends AsyncTask<String,String,String> { @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(Addstudent.this); progressDialog.setMessage("Please wait......"); progressDialog.setCanceledOnTouchOutside(false); progressDialog.show(); }
@Override protected String doInBackground(String... params) { try { List<NameValuePair> args = new ArrayList<>(); args.add(new BasicNameValuePair("rollno",rollString)); args.add(new BasicNameValuePair("name",nameString)); args.add(new BasicNameValuePair("phone",mobileString)); args.add(new BasicNameValuePair("mail",mailString)); args.add(new BasicNameValuePair("password",passwordString));
JSONObject jsonObject = parser.makeHttpRequest(addUrl, "POST", args);
} catch (Exception e) {
} return null; }
@Override protected void onPostExecute(String s) { super.onPostExecute(s);
progressDialog.dismiss(); Intent in=new Intent(Addstudent.this,StudentList.class); startActivity(in);
} }}
AdminHomeActivity.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;
public class AdminHomeActivity extends Activity implements View.OnClickListener{
Button facultyButton,studentButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_admin_home);
facultyButton= (Button) findViewById(R.id.faulty); studentButton= (Button) findViewById(R.id.student);
facultyButton.setOnClickListener(this); studentButton.setOnClickListener(this); }
@Override public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_admin_home, menu); return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId();
//noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; }
return super.onOptionsItemSelected(item); }
@Override public void onClick(View v) {
int id=v.getId(); if(id==R.id.faulty) { Intent fa=new Intent(AdminHomeActivity.this,FacultyList.class); startActivity(fa); } else if(id==R.id.student) { Intent st=new Intent(AdminHomeActivity.this,StudentList.class); startActivity(st); }
}}
AdminLoin.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;
import android.widget.EditText;import android.widget.Toast;
public class Adminlogin extends Activity {
EditText usernameEdit,passwordEdit; Button adminloginButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_adminlogin);
usernameEdit= (EditText) findViewById(R.id.adminusername); passwordEdit= (EditText) findViewById(R.id.adminpassword);
adminloginButton= (Button) findViewById(R.id.adminlogin); adminloginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
if(usernameEdit.getText().toString().equals("admin")&&passwordEdit.getText().toString().equals("admin")) { Intent in = new Intent(Adminlogin.this, AdminHomeActivity.class); startActivity(in); } else { Toast.makeText(Adminlogin.this,"Invalid username or password",Toast.LENGTH_LONG).show(); } } }); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_adminlogin, menu); return true; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; }
return super.onOptionsItemSelected(item); }}
Attendanceviewing.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Attendanceviewing extends Activity {
ListView vaList;
ProgressDialog progressDialog;
JSONParser parser=new JSONParser();
JSONArray response;
public String studentlistUrl="http://www.wikihands.com/attendanceandmarks/getattendance.php";
String getRoll;
ArrayList<String> statusArray=new ArrayList<>();
ArrayList<String> dateArray=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_attendanceviewing);
vaList= (ListView) findViewById(R.id.viewattendance);
}
@Override
protected void onResume() {
super.onResume();
getRoll=getIntent().getStringExtra("ROLLNO");
statusArray.clear();
dateArray.clear();
new attendancelist().execute();
}
public class attendancelist extends AsyncTask<String,String,String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=new ProgressDialog(Attendanceviewing.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
args.add(new BasicNameValuePair("rollno",getRoll));
JSONObject object = parser.makeHttpRequest(studentlistUrl, "POST", args);
response = object.getJSONArray("attendancedetails");
for(int i=0;i<response.length();i++)
{
JSONObject c=response.getJSONObject(i);
String status=c.getString("status");
String date=c.getString("date");
statusArray.add(status);
dateArray.add(date);
}
}catch (Exception e)
{
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
vaList.setAdapter(new attendanceadapter());
progressDialog.dismiss();
}
}
public class attendanceadapter extends BaseAdapter
{
@Override
public int getCount() {
return statusArray.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView=getLayoutInflater().inflate(R.layout.attendancelist,null);
TextView status= (TextView) convertView.findViewById(R.id.status);
TextView datetime= (TextView) convertView.findViewById(R.id.date);
status.setText(statusArray.get(position).toString());
datetime.setText(dateArray.get(position).toString());
return convertView;
}
}
}
EditStudentActivity.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class EditStudentActivity extends Activity {
EditText nameEdit,mobileEdit,emailEdit;
Button updateButton;
ProgressDialog progressDialog;
public static String update_Url="http://www.wikihands.com/attendanceandmarks/updatestudent.php";
JSONParser parser=new JSONParser();
JSONArray response;
String nameString,mobileString,emailString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_student);
progressDialog=new ProgressDialog(EditStudentActivity.this);
nameEdit= (EditText) findViewById(R.id.sname);
mobileEdit= (EditText) findViewById(R.id.smobile);
emailEdit= (EditText) findViewById(R.id.semail);
updateButton= (Button) findViewById(R.id.update);
nameEdit.setText(getIntent().getStringExtra("name"));
mobileEdit.setText(getIntent().getStringExtra("mobile"));
emailEdit.setText(getIntent().getStringExtra("email"));
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nameString = nameEdit.getText().toString();
mobileString = mobileEdit.getText().toString();
emailString = emailEdit.getText().toString();
if (nameString.length() > 0 && mobileString.length() > 0 && emailString.length() > 0) {
new Updatestudent().execute();
} else {
Toast.makeText(EditStudentActivity.this, "Make sure fill all the details", Toast.LENGTH_LONG).show();
}
}
});
}
public class Updatestudent extends AsyncTask<String,String,String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog.setMessage("Please wait....");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
args.add(new BasicNameValuePair("rollno",getIntent().getStringExtra("rollno")));
args.add(new BasicNameValuePair("name",nameString));
args.add(new BasicNameValuePair("mobile",mobileString));
args.add(new BasicNameValuePair("email",emailString));
JSONObject object = parser.makeHttpRequest(update_Url, "POST", args);
// response = object.getJSONArray("");
}catch (Exception e)
{
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
Toast.makeText(EditStudentActivity.this,"Updated successfully",Toast.LENGTH_LONG).show();
}
}
}
FacultyHome.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class FacultyHome extends Activity implements View.OnClickListener{
Button takeButton, viewButton, marksButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_faculty_home);
takeButton= (Button) findViewById(R.id.takeattendance);
viewButton= (Button) findViewById(R.id.viewattendance);
marksButton= (Button) findViewById(R.id.viewmarks);
takeButton.setOnClickListener(this);
viewButton.setOnClickListener(this);
marksButton.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_faculty_home, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
int id=v.getId();
if(id==R.id.takeattendance)
{
Intent in=new Intent(FacultyHome.this,Takeattendance.class);
startActivity(in);
}
else if(id==R.id.viewattendance)
{
Intent in=new Intent(FacultyHome.this,Viewattendance.class);
startActivity(in);
}
else if (id==R.id.viewmarks)
{
Intent in=new Intent(FacultyHome.this,ViewMarks.class);
startActivity(in);
}
}
}
FacultyList.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class FacultyList extends Activity {
Button addfacultyButton;
ListView facultylistView;
ProgressDialog progressDialog;
JSONParser parser = new JSONParser();
JSONArray response;
public String facultylistUrl = "http://www.wikihands.com/attendanceandmarks/facultylist.php";
ArrayList<String> facultynameArray = new ArrayList<>();
ArrayList<String> facultymobileArray = new ArrayList<>();
ArrayList<String> facultymailArray = new ArrayList<>();
ArrayList<String> facultydepartArray = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_faculty_list);
addfacultyButton = (Button) findViewById(R.id.addfaculty);
facultylistView = (ListView) findViewById(R.id.faultylist);
addfacultyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent in = new Intent(FacultyList.this, Addfaculty.class);
startActivity(in);
}
});
facultylistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent in = new Intent(FacultyList.this, Viewdetails.class);
in.putExtra("fname", facultynameArray.get(position).toString());
in.putExtra("fmobile", facultymobileArray.get(position).toString());
in.putExtra("fmail", facultymailArray.get(position).toString());
in.putExtra("fdepart", facultydepartArray.get(position).toString());
startActivity(in);
}
});
}
@Override
protected void onResume() {
super.onResume();
facultynameArray.clear();
facultymobileArray.clear();
facultymailArray.clear();
facultydepartArray.clear();
new viewfacultylist().execute();
}
public class viewfacultylist extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(FacultyList.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
JSONObject object = parser.makeHttpRequest(facultylistUrl, "GET", args);
response = object.getJSONArray("facultylist");
for (int i = 0; i < response.length(); i++) {
JSONObject c = response.getJSONObject(i);
String fname = c.getString("name");
String fmobile = c.getString("phone");
String fmail = c.getString("mail");
String fdepart=c.getString("department");
facultynameArray.add(fname);
facultymobileArray.add(fmobile);
facultymailArray.add(fmail);
facultydepartArray.add(fdepart);
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
ArrayAdapter<String> fadapter = new ArrayAdapter<String>(FacultyList.this, android.R.layout.simple_list_item_1, facultynameArray);
facultylistView.setAdapter(fadapter);
progressDialog.dismiss();
}
}
}
FacultyLogin.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class FacultyLogin extends Activity {
EditText ftusername,ftpassword;
Button ftlogin;
String userString,passString;
ProgressDialog progressDialog;
JSONParser parser=new JSONParser();
JSONArray response;
public String floginUrl="http://www.wikihands.com/attendanceandmarks/facultylogin.php";
String resUser,resPass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_faculty_login);
ftusername= (EditText) findViewById(R.id.facultyusername);
ftpassword= (EditText) findViewById(R.id.facultypassword);
ftlogin= (Button) findViewById(R.id.facultylogin);
ftlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
userString=ftusername.getText().toString();
passString=ftpassword.getText().toString();
new facultylogin().execute();
}
});
}
public class facultylogin extends AsyncTask<String,String,String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=new ProgressDialog(FacultyLogin.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
args.add(new BasicNameValuePair("username",userString));
JSONObject object=parser.makeHttpRequest(floginUrl,"POST",args);
response=object.getJSONArray("facultylogin");
for(int i=0;i<response.length();i++)
{
JSONObject c=response.getJSONObject(i);
resUser=c.getString("username");
resPass=c.getString("password");
}
}catch (Exception e)
{
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(userString.equals(resUser)&&passString.equals(resPass))
{
Intent in=new Intent(FacultyLogin.this,FacultyHome.class);
startActivity(in);
}
else
{
Toast.makeText(FacultyLogin.this,"Invalid Username or Password",Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
}
}
HomeActivity.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class HomeActivity extends Activity implements View.OnClickListener{
Button adminButton,facultyButton,parentButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
adminButton= (Button) findViewById(R.id.admin);
facultyButton= (Button) findViewById(R.id.faulty);
parentButton= (Button) findViewById(R.id.parent);
adminButton.setOnClickListener(this);
facultyButton.setOnClickListener(this);
parentButton.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_home, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
int id=v.getId();
if(id==R.id.admin)
{
Intent adm=new Intent(HomeActivity.this,Adminlogin.class);
startActivity(adm);
}
else if(id==R.id.faulty)
{
Intent ft=new Intent(HomeActivity.this,FacultyLogin.class);
startActivity(ft);
}
else if(id==R.id.parent)
{
Intent pt=new Intent(HomeActivity.this,ParentLogin.class);
startActivity(pt);
}
}
}
JSONParser.java
package com.gpslocation.attendanceandmarkssystem;
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
// function get json from url
// by making HTTP POST or GET mehtod
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
else if(method=="PUT")
{
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpPut httpGet = new HttpPut(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
ParentHomeScreen.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class ParentHomeScreen extends Activity implements View.OnClickListener {
Button pviewattendanceButton, pmarksButton;
String getRoll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_parent_home_screen);
pviewattendanceButton = (Button) findViewById(R.id.pviewattendance);
pmarksButton = (Button) findViewById(R.id.pviewmarks);
pviewattendanceButton.setOnClickListener(this);
pmarksButton.setOnClickListener(this);
}
@Override
protected void onResume() {
super.onResume();
getRoll = getIntent().getStringExtra("rollno");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_parent_home_screen, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.pviewattendance) {
Intent in = new Intent(ParentHomeScreen.this, Attendanceviewing.class);
in.putExtra("ROLLNO", getRoll);
startActivity(in);
} else if (id == R.id.pviewmarks) {
Intent in = new Intent(ParentHomeScreen.this, ViewMarks.class);
startActivity(in);
}
}
}
ParentLogin.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class ParentLogin extends Activity {
EditText prollEdit;
Button psubmitButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_parent_login);
prollEdit= (EditText) findViewById(R.id.prollno);
psubmitButton= (Button) findViewById(R.id.psubmit);
psubmitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rollString=prollEdit.getText().toString();
Intent in=new Intent(ParentLogin.this,ParentHomeScreen.class);
in.putExtra("rollno",rollString);
startActivity(in);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_parent_login, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
SplashScreen.java
package com.gpslocation.attendanceandmarkssystem;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
Thread background = new Thread() {
public void run()
{
try
{
sleep(5*1000);
Intent in=new Intent(SplashScreen.this,HomeActivity.class);
startActivity(in);
finish();
}catch (Exception e)
{
}
}
};
background.start();
}
}
Studentdetails.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.List;
public class Studentdetails extends Activity implements View.OnClickListener {
TextView sdetails;
Button editButton, deleteButton;
ProgressDialog progressDialog;
public static String delete_Url = "http://www.wikihands.com/attendanceandmarks/deletestudent.php";
JSONParser parser = new JSONParser();
JSONArray response;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_studentdetails);
progressDialog = new ProgressDialog(Studentdetails.this);
sdetails = (TextView) findViewById(R.id.studentdetails);
editButton = (Button) findViewById(R.id.edit);
deleteButton = (Button) findViewById(R.id.delete);
String getroll = getIntent().getStringExtra("rollno");
String getname = getIntent().getStringExtra("name");
String getmobile = getIntent().getStringExtra("mobile");
String getmail = getIntent().getStringExtra("mail");
editButton.setOnClickListener(this);
deleteButton.setOnClickListener(this);
sdetails.setText("Roll no: " + getroll + "\nName: " + getname + "\nMobile: " + getmobile + "\nE-mail: " + getmail);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_studentdetails, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.edit) {
Intent intent=new Intent(Studentdetails.this,EditStudentActivity.class);
intent.putExtra("rollno",getIntent().getStringExtra("rollno"));
intent.putExtra("name",getIntent().getStringExtra("name"));
intent.putExtra("mobile",getIntent().getStringExtra("mobile"));
intent.putExtra("email",getIntent().getStringExtra("mail"));
startActivity(intent);
} else if (id == R.id.delete) {
new Deletestudent().execute();
}
}
public class Deletestudent extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog.setMessage("Please wait....");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
args.add(new BasicNameValuePair("rollno", getIntent().getStringExtra("rollno")));
JSONObject object = parser.makeHttpRequest(delete_Url, "POST", args);
// response = object.getJSONArray("");
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
Intent in = new Intent(Studentdetails.this, StudentList.class);
startActivity(in);
}
}
}
StudentList.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class StudentList extends Activity {
Button addstudentButton;
ListView studentlistView;
ProgressDialog progressDialog;
JSONParser parser=new JSONParser();
JSONArray response;
public String studentlistUrl="http://www.wikihands.com/attendanceandmarks/studentlist.php";
ArrayList<String> studentrollArray=new ArrayList<>();
ArrayList<String> studentnameArray=new ArrayList<>();
ArrayList<String> studentmobileArray=new ArrayList<>();
ArrayList<String> studentmailArray=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_list);
addstudentButton= (Button) findViewById(R.id.addstudent);
studentlistView= (ListView) findViewById(R.id.studentlist);
addstudentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent in=new Intent(StudentList.this,Addstudent.class);
startActivity(in);
}
});
studentlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent in=new Intent(StudentList.this,Studentdetails.class);
in.putExtra("rollno",studentrollArray.get(position).toString());
in.putExtra("name",studentnameArray.get(position).toString());
in.putExtra("mobile",studentmobileArray.get(position).toString());
in.putExtra("mail",studentmailArray.get(position).toString());
startActivity(in);
}
});
}
@Override
protected void onResume() {
super.onResume();
studentnameArray.clear();
new viewstudentlist().execute();
}
public class viewstudentlist extends AsyncTask<String,String,String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=new ProgressDialog(StudentList.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
JSONObject object = parser.makeHttpRequest(studentlistUrl, "GET", args);
response = object.getJSONArray("studentlist");
for(int i=0;i<response.length();i++)
{
JSONObject c=response.getJSONObject(i);
String sroll=c.getString("rollno");
String sname=c.getString("name");
String smobile=c.getString("phone");
String smail=c.getString("mail");
studentrollArray.add(sroll);
studentnameArray.add(sname);
studentmobileArray.add(smobile);
studentmailArray.add(smail);
}
}catch (Exception e)
{
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
ArrayAdapter<String> sadapter=new ArrayAdapter<String>(StudentList.this,android.R.layout.simple_list_item_1,studentnameArray);
studentlistView.setAdapter(sadapter);
progressDialog.dismiss();
}
}
}
Takeattendance.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Takeattendance extends Activity {
ListView takeList;
Button submitButton;
ProgressDialog progressDialog;
JSONParser parser = new JSONParser();
JSONArray response;
public String studentattendanceUrl = "http://www.wikihands.com/attendanceandmarks/attendance.php";
public String studentlistUrl = "http://www.wikihands.com/attendanceandmarks/studentlist.php";
ArrayList<String> checkedList = new ArrayList<>();
ArrayList<String> uncheckedList = new ArrayList<>();
ArrayList<String> checkmobileList = new ArrayList<>();
ArrayList<String> uncheckmobileList = new ArrayList<>();
ArrayList<String> studentlistArray = new ArrayList<>();
ArrayList<String> studentmobileArray = new ArrayList<>();
String message;
String[] timeArray = {"Select Time","07:10AM","07:15AM","08:15AM","08:45AM","09:15AM", "9:30AM", "10:00AM", "11:00AM","11:30AM",
"12:00PM","12:30PM", "02:00PM", "02:30PM","03:30PM","04:00PM"};
String timeString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_takeattendance);
submitButton = (Button) findViewById(R.id.submitattendance);
takeList = (ListView) findViewById(R.id.stlist);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog d = new Dialog(Takeattendance.this);
d.setContentView(R.layout.take);
d.setTitle(" Give your details");
final EditText sub = (EditText) d.findViewById(R.id.subject);
Spinner time = (Spinner) d.findViewById(R.id.time);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Takeattendance.this, android.R.layout.simple_list_item_1, timeArray);
time.setAdapter(adapter);
time.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
timeString = parent.getItemAtPosition(position).toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Button send = (Button) d.findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
message = sub.getText().toString();
new uploadattendance().execute();
d.dismiss();
}
});
d.show();
}
});
}
@Override
protected void onResume() {
super.onResume();
studentlistArray.clear();
new getstudents().execute();
}
public class getstudents extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(Takeattendance.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
JSONObject object = parser.makeHttpRequest(studentlistUrl, "GET", args);
response = object.getJSONArray("studentlist");
for (int i = 0; i < response.length(); i++) {
JSONObject c = response.getJSONObject(i);
// String sroll = c.getString("rollno");
String sname=c.getString("name");
String smobile = c.getString("phone");
studentlistArray.add(sname);
studentmobileArray.add(smobile);
uncheckedList.add(sname);
uncheckmobileList.add(smobile);
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
takeList.setAdapter(new studentAdapter());
progressDialog.dismiss();
}
}
public class studentAdapter extends BaseAdapter {
@Override
public int getCount() {
return studentlistArray.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = getLayoutInflater().inflate(R.layout.rollnumberlist, null);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.rollCheck);
checkBox.setText(studentlistArray.get(position));
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked == true) {
// Toast.makeText(StudentList.this,"true"+position,Toast.LENGTH_SHORT).show();
checkedList.add(studentlistArray.get(position).toString());
uncheckedList.remove(studentlistArray.get(position).toString());
checkmobileList.add(studentmobileArray.get(position).toString());
uncheckmobileList.remove(studentmobileArray.get(position).toString());
}
if (isChecked == false) {
// Toast.makeText(StudentList.this,"false"+position,Toast.LENGTH_SHORT).show();
checkedList.remove(studentlistArray.get(position).toString());
uncheckedList.add(studentlistArray.get(position).toString());
checkmobileList.remove(studentmobileArray.get(position).toString());
uncheckmobileList.add(studentmobileArray.get(position).toString());
}
}
});
return convertView;
}
}
public class uploadattendance extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(Takeattendance.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
List<NameValuePair> args = new ArrayList<>();
for (int p = 0; p < checkedList.size(); p++) {
args.add(new BasicNameValuePair("rollno", checkedList.get(p).toString()));
args.add(new BasicNameValuePair("status", "A"));
JSONObject object = parser.makeHttpRequest(studentattendanceUrl, "POST", args);
}
for (int p = 0; p < uncheckedList.size(); p++) {
args.add(new BasicNameValuePair("rollno", uncheckedList.get(p).toString()));
args.add(new BasicNameValuePair("status", "P"));
JSONObject object = parser.makeHttpRequest(studentattendanceUrl, "POST", args);
}
for (int p = 0; p < checkmobileList.size(); p++) {
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(checkmobileList.get(p).toString(), null, "Your ward is absent for class '"+message+"' at '"+timeString+"'. Please contact N.Lavanya 8297225625 ", null, null);
Log.v("dddddddd", "" + checkmobileList.toString());
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
}
}
}
Viewattendance.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Takeattendance extends Activity {
ListView takeList;
Button submitButton;
ProgressDialog progressDialog;
JSONParser parser = new JSONParser();
JSONArray response;
public String studentattendanceUrl = "http://www.wikihands.com/attendanceandmarks/attendance.php";
public String studentlistUrl = "http://www.wikihands.com/attendanceandmarks/studentlist.php";
ArrayList<String> checkedList = new ArrayList<>();
ArrayList<String> uncheckedList = new ArrayList<>();
ArrayList<String> checkmobileList = new ArrayList<>();
ArrayList<String> uncheckmobileList = new ArrayList<>();
ArrayList<String> studentlistArray = new ArrayList<>();
ArrayList<String> studentmobileArray = new ArrayList<>();
String message;
String[] timeArray = {"Select Time","07:10AM","07:15AM","08:15AM","08:45AM","09:15AM", "9:30AM", "10:00AM", "11:00AM","11:30AM",
"12:00PM","12:30PM", "02:00PM", "02:30PM","03:30PM","04:00PM"};
String timeString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_takeattendance);
submitButton = (Button) findViewById(R.id.submitattendance);
takeList = (ListView) findViewById(R.id.stlist);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog d = new Dialog(Takeattendance.this);
d.setContentView(R.layout.take);
d.setTitle(" Give your details");
final EditText sub = (EditText) d.findViewById(R.id.subject);
Spinner time = (Spinner) d.findViewById(R.id.time);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Takeattendance.this, android.R.layout.simple_list_item_1, timeArray);
time.setAdapter(adapter);
time.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
timeString = parent.getItemAtPosition(position).toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Button send = (Button) d.findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
message = sub.getText().toString();
new uploadattendance().execute();
d.dismiss();
}
});
d.show();
}
});
}
@Override
protected void onResume() {
super.onResume();
studentlistArray.clear();
new getstudents().execute();
}
public class getstudents extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(Takeattendance.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
JSONObject object = parser.makeHttpRequest(studentlistUrl, "GET", args);
response = object.getJSONArray("studentlist");
for (int i = 0; i < response.length(); i++) {
JSONObject c = response.getJSONObject(i);
// String sroll = c.getString("rollno");
String sname=c.getString("name");
String smobile = c.getString("phone");
studentlistArray.add(sname);
studentmobileArray.add(smobile);
uncheckedList.add(sname);
uncheckmobileList.add(smobile);
}
} catch (Exception e) {
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
takeList.setAdapter(new studentAdapter());
progressDialog.dismiss();
}
}
public class studentAdapter extends BaseAdapter {
@Override
public int getCount() {
return studentlistArray.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = getLayoutInflater().inflate(R.layout.rollnumberlist, null);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.rollCheck);
checkBox.setText(studentlistArray.get(position));
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked == true) {
// Toast.makeText(StudentList.this,"true"+position,Toast.LENGTH_SHORT).show();
checkedList.add(studentlistArray.get(position).toString());
uncheckedList.remove(studentlistArray.get(position).toString());
checkmobileList.add(studentmobileArray.get(position).toString());
uncheckmobileList.remove(studentmobileArray.get(position).toString());
}
if (isChecked == false) {
// Toast.makeText(StudentList.this,"false"+position,Toast.LENGTH_SHORT).show();
checkedList.remove(studentlistArray.get(position).toString());
uncheckedList.add(studentlistArray.get(position).toString());
checkmobileList.remove(studentmobileArray.get(position).toString());
uncheckmobileList.add(studentmobileArray.get(position).toString());
}
}
});
return convertView;
}
}
public class uploadattendance extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(Takeattendance.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
List<NameValuePair> args = new ArrayList<>();
for (int p = 0; p < checkedList.size(); p++) {
args.add(new BasicNameValuePair("rollno", checkedList.get(p).toString()));
args.add(new BasicNameValuePair("status", "A"));
JSONObject object = parser.makeHttpRequest(studentattendanceUrl, "POST", args);
}
for (int p = 0; p < uncheckedList.size(); p++) {
args.add(new BasicNameValuePair("rollno", uncheckedList.get(p).toString()));
args.add(new BasicNameValuePair("status", "P"));
JSONObject object = parser.makeHttpRequest(studentattendanceUrl, "POST", args);
}
for (int p = 0; p < checkmobileList.size(); p++) {
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(checkmobileList.get(p).toString(), null, "Your ward is absent for class '"+message+"' at '"+timeString+"'. Please contact N.Lavanya 8297225625 ", null, null);
Log.v("dddddddd", "" + checkmobileList.toString());
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
}
}
}
Viewattendance.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Viewattendance extends Activity {
ListView vlistview;
ProgressDialog progressDialog;
JSONParser parser=new JSONParser();
JSONArray response;
public String studentlistUrl="http://www.wikihands.com/attendanceandmarks/studentlist.php";
ArrayList<String> rollnolistArray=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewattendance);
vlistview= (ListView) findViewById(R.id.vlist);
vlistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent in=new Intent(Viewattendance.this,Attendanceviewing.class);
in.putExtra("ROLLNO",rollnolistArray.get(position).toString());
startActivity(in);
}
});
}
@Override
protected void onResume() {
super.onResume();
rollnolistArray.clear();
new getstudents().execute();
}
public class getstudents extends AsyncTask<String,String,String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=new ProgressDialog(Viewattendance.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try {
List<NameValuePair> args = new ArrayList<>();
JSONObject object = parser.makeHttpRequest(studentlistUrl, "GET", args);
response = object.getJSONArray("studentlist");
for(int i=0;i<response.length();i++)
{
JSONObject c=response.getJSONObject(i);
String sroll=c.getString("rollno");
String sname=c.getString("name");
rollnolistArray.add(sname);
}
}catch (Exception e)
{
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
ArrayAdapter<String> vadapter=new ArrayAdapter<String>(Viewattendance.this,android.R.layout.simple_list_item_1,rollnolistArray);
vlistview.setAdapter(vadapter);
progressDialog.dismiss();
}
}
}
Viewdetail.java
package com.gpslocation.attendanceandmarkssystem;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class Viewdetails extends Activity {
TextView detailsTextview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewdetails);
detailsTextview= (TextView) findViewById(R.id.details);
String getname=getIntent().getStringExtra("fname");
String getmobile=getIntent().getStringExtra("fmobile");
String getmail=getIntent().getStringExtra("fmail");
String getdepart=getIntent().getStringExtra("fdepart");
detailsTextview.setText("Name: "+getname+"\nMobile: "+getmobile+"\nE-mail: "+getmail+"\nDepartment: "+getdepart);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_viewdetails, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
ViewMasks.java
package com.gpslocation.attendanceandmarkssystem;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
public class ViewMarks extends Activity {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_marks);
WebView htmlWebView = (WebView)findViewById(R.id.web);
WebSettings webSetting = htmlWebView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setDisplayZoomControls(true);
String htmlFilename = "marksheet.html";
AssetManager mgr = getBaseContext().getAssets();
try {
InputStream in = mgr.open(htmlFilename, AssetManager.ACCESS_BUFFER);
String htmlContentInStringFormat = StreamToString(in);
in.close();
htmlWebView.loadDataWithBaseURL(null, htmlContentInStringFormat, "text/html", "utf-8", null);
} catch (IOException e) {
e.printStackTrace();
}
}
public static String StreamToString(InputStream in) throws IOException {
if(in == null) {
return "";
}
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
}
return writer.toString();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_view_marks, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}