0% found this document useful (0 votes)
24 views9 pages

Studentreportactivity

Uploaded by

Uday Kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views9 pages

Studentreportactivity

Uploaded by

Uday Kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

package app.sams.hassoft.com.

iev;

import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Base64;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.google.gson.Gson;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import app.sams.hassoft.com.iev.dtos.CenterInfoDTO;
import app.sams.hassoft.com.iev.dtos.CenterParams;
import app.sams.hassoft.com.iev.dtos.DistrictSchoolSummaryDTO;
import app.sams.hassoft.com.iev.dtos.SchoolSummaryDTO;

public class StudentReportActivity extends AppCompatActivity implements


View.OnClickListener {
private static String TAG = "StudentReport";
private ListView listView;
private DatePickerDialog attendanceDatePickerPopup;
private SimpleDateFormat dateFormatter;
private String date;
private EditText datefield;
private CenterInfoDTO[] centers;
private StudentReportAdapter studentReportAdapter;

private LinearLayout gl1;


private ImageView ev1;
private LinearLayout gl2;
private ImageView ev2;
private LinearLayout gl3;
private ImageView ev3;
private LinearLayout gl4;
private ImageView ev4;
private LinearLayout gl5;
private ImageView ev5;
private LinearLayout gl6;
private ImageView ev6;
private LinearLayout gl7;
private ImageView ev7;
private LinearLayout gl8;
private ImageView ev8;
private LinearLayout gl9;
private ImageView ev9;
private LinearLayout gl10;
private ImageView ev10;
private LinearLayout gl11;
private ImageView ev11;
private LinearLayout gl12;
private ImageView ev12;
private LinearLayout gl13;
private ImageView ev13;

private TextView t1;


private TextView t2;
private TextView t3;
private TextView t4;
private TextView t5;
private TextView t6;
private TextView t7;
private TextView t8;
private TextView t9;
private TextView t10;
private TextView t11;
private TextView t12;
private TextView t13;

private LinearLayout lmain;


private ImageView imain;
private String selectedRadioGroup;
private SchoolSummaryDTO students;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_student_report);

dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);

ActionBar actionBar = getSupportActionBar();


actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.drawable.ic_iev);
actionBar.setDisplayHomeAsUpEnabled(true);
Intent centersIntent = getIntent();
date = centersIntent.getStringExtra("date");
selectedRadioGroup = centersIntent.getStringExtra("selectedRadioGroup");
initializeFields();
setDateTimeField();
try {
//centers = new
SchoolActivity.VisualService().execute(datefield.getText().toString(),"Ananthapur")
.get();
populateData("Ananthapur");
populateDataLabel();
} catch (Exception e) {
return;
}

initializeFields();

private void initializeFields() {


gl1 = (LinearLayout) findViewById(R.id.stdrepgdistrict1);
ev1 = (ImageView) findViewById(R.id.stdrepidistrict1);
gl1.setOnClickListener(this);
ev1.setOnClickListener(this);
gl2 = (LinearLayout) findViewById(R.id.stdrepgdistrict2);
ev2 = (ImageView) findViewById(R.id.stdrepidistrict2);

gl3 = (LinearLayout) findViewById(R.id.stdrepgdistrict3);


ev3 = (ImageView) findViewById(R.id.stdrepidistrict3);

gl4 = (LinearLayout) findViewById(R.id.stdrepgdistrict4);


ev4 = (ImageView) findViewById(R.id.stdrepidistrict4);

gl5 = (LinearLayout) findViewById(R.id.stdrepgdistrict5);


ev5 = (ImageView) findViewById(R.id.stdrepidistrict5);

gl6 = (LinearLayout) findViewById(R.id.stdrepgdistrict6);


ev6 = (ImageView) findViewById(R.id.stdrepidistrict6);

gl7 = (LinearLayout) findViewById(R.id.stdrepgdistrict7);


ev7 = (ImageView) findViewById(R.id.stdrepidistrict7);

gl8 = (LinearLayout) findViewById(R.id.stdrepgdistrict8);


ev8 = (ImageView) findViewById(R.id.stdrepidistrict8);

gl9 = (LinearLayout) findViewById(R.id.stdrepgdistrict9);


ev9 = (ImageView) findViewById(R.id.stdrepidistrict9);

gl10 = (LinearLayout) findViewById(R.id.stdrepgdistrict10);


ev10 = (ImageView) findViewById(R.id.stdrepidistrict10);

gl11 = (LinearLayout) findViewById(R.id.stdrepgdistrict11);


ev11 = (ImageView) findViewById(R.id.stdrepidistrict11);

gl12 = (LinearLayout) findViewById(R.id.stdrepgdistrict12);


ev12 = (ImageView) findViewById(R.id.stdrepidistrict12);

gl13 = (LinearLayout) findViewById(R.id.stdrepgdistrict13);


ev13 = (ImageView) findViewById(R.id.stdrepidistrict13);
/*

lmain = (LinearLayout) findViewById(R.id.stdrepchmlmain);


imain = (ImageView) findViewById(R.id.stdrepchmimain);

lmain.setOnClickListener(this);
imain.setOnClickListener(this);
*/

gl2.setOnClickListener(this);
ev2.setOnClickListener(this);

gl3.setOnClickListener(this);
ev3.setOnClickListener(this);

gl4.setOnClickListener(this);
ev4.setOnClickListener(this);

gl5.setOnClickListener(this);
ev5.setOnClickListener(this);

gl6.setOnClickListener(this);
ev6.setOnClickListener(this);

gl7.setOnClickListener(this);
ev7.setOnClickListener(this);

gl8.setOnClickListener(this);
ev8.setOnClickListener(this);

gl9.setOnClickListener(this);
ev9.setOnClickListener(this);

gl10.setOnClickListener(this);
ev10.setOnClickListener(this);

gl11.setOnClickListener(this);
ev11.setOnClickListener(this);

gl12.setOnClickListener(this);
ev12.setOnClickListener(this);

gl13.setOnClickListener(this);
ev13.setOnClickListener(this);
t1 = (TextView) findViewById(R.id.stdreptxt1);
t2 = (TextView) findViewById(R.id.stdreptxt2);
t3 = (TextView) findViewById(R.id.stdreptxt3);
t4 = (TextView) findViewById(R.id.stdreptxt4);
t5 = (TextView) findViewById(R.id.stdreptxt5);
t6 = (TextView) findViewById(R.id.stdreptxt6);
t7 = (TextView) findViewById(R.id.stdreptxt7);
t8 = (TextView) findViewById(R.id.stdreptxt8);
t9 = (TextView) findViewById(R.id.stdreptxt9);
t10 = (TextView) findViewById(R.id.stdreptxt10);
t11 = (TextView) findViewById(R.id.stdreptxt11);
t12 = (TextView) findViewById(R.id.stdreptxt12);
t13 = (TextView) findViewById(R.id.stdreptxt13);

private void populateData(String district) {

/*String[] ldate = date.split("-");


Calendar newDate = Calendar.getInstance();
newDate.set(Integer.parseInt(ldate[2]), Integer.parseInt(ldate[1]) - 1,
Integer.parseInt(ldate[0]));
datefield.setText(dateFormatter.format(newDate.getTime()));*/
try {
CenterParams params = new CenterParams();
params.setDate(datefield.getText().toString());
params.setDistrict(district);
centers = new
StudentReportActivity.VisualService().execute(params).get();
} catch (Exception e) {
return;
}
listView = (ListView) findViewById(R.id.stdrepclistview);
List<CenterInfoDTO> listdata = new ArrayList<CenterInfoDTO>();
for (CenterInfoDTO c : centers) {
if (c.getDistrict_name().equalsIgnoreCase(district))
listdata.add(c);
}
studentReportAdapter = new StudentReportAdapter(new
ArrayList<CenterInfoDTO>(listdata), getApplicationContext());
listView.setAdapter(studentReportAdapter);
listView.invalidate();
populateDataLabel();
}

private void populateDataLabel() {


/* String[] ldate = date.split("-");
Calendar newDate = Calendar.getInstance();
newDate.set(Integer.parseInt(ldate[2]), Integer.parseInt(ldate[1]) - 1,
Integer.parseInt(ldate[0]));
datefield.setText(dateFormatter.format(newDate.getTime()));*/
try {

students = new
StudentReportActivity.SummaryVisualService().execute(datefield.getText().toString()
).get();

HashMap<String, DistrictSchoolSummaryDTO> dists = new HashMap<String,


DistrictSchoolSummaryDTO>();
for (DistrictSchoolSummaryDTO ob : students.getSummary()) {
dists.put(ob.getSch_name(), ob);

} catch (Exception e) {
e.printStackTrace();
return;
}

}
public boolean onOptionsItemSelected(MenuItem item){
Intent mainIntent = new Intent(getApplicationContext(), Dashboard.class);
mainIntent.putExtra("date", date);
mainIntent.putExtra("selectedRadioGroup", selectedRadioGroup);
startActivityForResult(mainIntent, 0);
finish();
return true;
}
private void setDateTimeField() {
datefield = (EditText) findViewById(R.id.stdrepField);
datefield.setOnClickListener(this);

Calendar newCalendar = Calendar.getInstance();


Calendar newDate = Calendar.getInstance();
String[] d = date.split("-");
newDate.set(Integer.parseInt(d[2]), Integer.parseInt(d[1]) - 1,
Integer.parseInt(d[0]));

datefield.setText(dateFormatter.format(newDate.getTime()));

attendanceDatePickerPopup = new DatePickerDialog(this, new


DatePickerDialog.OnDateSetListener() {

public void onDateSet(DatePicker view, int year, int monthOfYear, int


dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
datefield.setText(dateFormatter.format(newDate.getTime()));
try {
//centers = new
SchoolActivity.VisualService().execute(datefield.getText().toString(),"Ananthapur")
.get();
populateData("Ananthapur");
} catch (Exception e) {
return;
}
listView = (ListView) findViewById(R.id.stdrepclistview);
List<CenterInfoDTO> listdata = new ArrayList<CenterInfoDTO>();
for (CenterInfoDTO c : centers) {
if (c.getDistrict_name().equalsIgnoreCase("Ananthapur"))
listdata.add(c);
}
studentReportAdapter = new StudentReportAdapter(new
ArrayList<CenterInfoDTO>(listdata), getApplicationContext());
listView.setAdapter(studentReportAdapter);
listView.invalidate();

}, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH),
newCalendar.get(Calendar.DAY_OF_MONTH));
//datefield.invalidate();
}

@Override
public void onClick(View v) {

if (v == datefield) {
attendanceDatePickerPopup.show();
}
if (v == gl1 || v == ev1) {
populateData("Ananthapur");
}
if (v == gl2 || v == ev2) {
populateData("Chittoor");
}
if (v == gl3 || v == ev3) {
populateData("Cuddapah");
}

if (v == gl4 || v == ev4) {
populateData("East Godavari");
}
if (v == gl5 || v == ev5) {
populateData("Guntur");
}
if (v == gl6 || v == ev6) {
populateData("Krishna");
}
if (v == gl7 || v == ev7) {
populateData("Kurnool");
}
if (v == gl8 || v == ev8) {
populateData("Nellore");
}
if (v == gl9 || v == ev9) {
populateData("Prakasam");
}
if (v == gl10 || v == ev10) {
populateData("Srikakulam");
}
if (v == gl11 || v == ev11) {
populateData("Vishakapatnam");
}
if (v == gl12 || v == ev12) {
populateData("Vizianagaram");
}
if (v == gl3 || v == ev13) {
populateData("West Godavari");
}

if (v == lmain || v == imain) {
Intent mainIntent = new Intent(v.getContext(), Dashboard.class);
mainIntent.putExtra("date", date);
mainIntent.putExtra("selectedRadioGroup", selectedRadioGroup);
startActivityForResult(mainIntent, 0);
finish();

public class VisualService extends AsyncTask<CenterParams, Void,


CenterInfoDTO[]> {

ProgressDialog loading;

protected CenterInfoDTO[] doInBackground(CenterParams... params) {


CenterInfoDTO[] lcenters = null;

try {

String plainCreds = "venkat:venkat";


final String url = getString(R.string.app_serviceapiurl) +
"getStudentReport";
byte[] plainCredsBytes = plainCreds.getBytes();
byte[] base64CredsBytes = Base64.encode(plainCredsBytes,
Base64.DEFAULT);
String base64Creds = new String(base64CredsBytes);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<Object> entity = new HttpEntity<Object>(params[0],


headers);
ResponseEntity<String> response = restTemplate.exchange(url,
HttpMethod.POST, entity, String.class);
String jsonString = response.getBody();
Gson gson = new Gson();
lcenters = GsonHelper.customGson.fromJson(jsonString,
CenterInfoDTO[].class);

} catch (Exception e) {
e.printStackTrace();
return null;
}

return lcenters;
}
}

public class SummaryVisualService extends AsyncTask<String, Void,


SchoolSummaryDTO> {

ProgressDialog loading;

protected SchoolSummaryDTO doInBackground(String... params) {


SchoolSummaryDTO students = null;

try {

String plainCreds = "venkat:venkat";


final String url = getString(R.string.app_serviceapiurl) +
"getStudentInfo";
byte[] plainCredsBytes = plainCreds.getBytes();
byte[] base64CredsBytes = Base64.encode(plainCredsBytes,
Base64.DEFAULT);
String base64Creds = new String(base64CredsBytes);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<Object> entity = new HttpEntity<Object>(params[0],


headers);
ResponseEntity<String> response = restTemplate.exchange(url,
HttpMethod.POST, entity, String.class);
String jsonString = response.getBody();
Gson gson = new Gson();
students = GsonHelper.customGson.fromJson(jsonString,
SchoolSummaryDTO.class);

} catch (Exception e) {
e.printStackTrace();
return null;
}

return students;
}

}
}

You might also like