Skip to content

Commit

Permalink
Merge pull request #119 from colegarien/ra_attendance_imrovment
Browse files Browse the repository at this point in the history
Added Note Functionality for Individual Student Attendance Records
  • Loading branch information
symbyte committed Nov 10, 2015
2 parents 007e8fc + ef3c447 commit 3f7af25
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import edu.uco.schambers.classmate.Fragments.StudentInterface;
import edu.uco.schambers.classmate.Fragments.StudentResponseFragment;
import edu.uco.schambers.classmate.Fragments.StudentRollCall;
import edu.uco.schambers.classmate.Fragments.TeacherAttendanceItem;
import edu.uco.schambers.classmate.Fragments.TeacherInterface;
import edu.uco.schambers.classmate.Fragments.TeacherQuestionResults;
import edu.uco.schambers.classmate.Fragments.UserInformation;
Expand Down Expand Up @@ -485,7 +486,11 @@ public void onBackPressed(){
if (f instanceof StudentRollCall && !((StudentRollCall) f).allowBackPressed()){
return;
}

//Back button will pop back stack in instances of teacher attendance item
//to allow pressing back only once
else if (f instanceof TeacherAttendanceItem){
getFragmentManager().popBackStack();
}
super.onBackPressed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void buildTable(View view, int position){
teacherAttendanceTable.bringToFront();
teacherAttendanceTable.removeAllViews();
//Loops through the entire list of students
for (StudentAbsenceByClass student : students) {
for (final StudentAbsenceByClass student : students) {
//If the current student's course is equal to the course chosen

//Store the number of absences
Expand All @@ -300,7 +300,7 @@ public boolean onTouch(View v, MotionEvent event) {
//Momentarily change background color to indicate the touch
v.setBackgroundColor(Color.GRAY);
//Set up a new fragment object
Fragment teacherAttendanceItem = TeacherAttendanceItem.newInstance(absences + "", "test");
Fragment teacherAttendanceItem = TeacherAttendanceItem.newInstance(absences + "", student.getName());
//Pass the attendance info, replace the current fragment, and place old
//fragment on the backstack
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Expand All @@ -318,7 +318,7 @@ public boolean onTouch(View v, MotionEvent event) {
TextView c0 = new TextView(view.getContext());
c0.setText(student.getName());
TextView c2 = new TextView(view.getContext());
c2.setText(String.valueOf(student.getAbsences()));
c2.setText(String.valueOf(4)); //student.getAbsences())
//Add the data to the row
tr.addView(c0);
tr.addView(c2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,53 @@
package edu.uco.schambers.classmate.Fragments;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.achartengine.ChartFactory;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.w3c.dom.Text;

import edu.uco.schambers.classmate.R;

public class TeacherAttendanceItem extends Fragment {
int absences;
private TextView missing, attendance;
String studentName;
String note;
AlertDialog.Builder alert;
private View mChart;
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
public static final String MyPREFS = "MyPREFS";
public static final String MySCHOOL = "MySCHOOL";
public SharedPreferences sp;
public SharedPreferences.Editor editor;
TextView tvNote;

public TeacherAttendanceItem() {
// Required empty public constructor
Expand All @@ -57,6 +78,9 @@ public static TeacherAttendanceItem newInstance(String param1, String param2) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
absences = Integer.parseInt(getArguments().getString(ARG_PARAM1));
studentName = getArguments().getString(ARG_PARAM2);
sp = getActivity().getSharedPreferences(MyPREFS, Context.MODE_PRIVATE);
editor = sp.edit();
}


Expand Down Expand Up @@ -105,28 +129,59 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

//@TargetApi(Build.VERSION_CODES.M)
private void initUI(final View rootView) {
tvNote = (TextView) rootView.findViewById(R.id.tvNote);
tvNote.setText(sp.getString("attNote-"+studentName,"N/A"));
alert = new AlertDialog.Builder(getActivity());
String[] titles = new String[]{" Attendance ", " Absences "};
int[] values = new int[]{10, absences};
missing = (TextView) rootView.findViewById(R.id.ra_tvAbsences);
attendance = (TextView) rootView.findViewById(R.id.ra_tvAttendance);
attendance.setText(10+"");
missing.setText(absences+"");
int[] values = new int[]{10, 4}; //absences
TextView tvStudentName = (TextView)rootView.findViewById(R.id.textView4);
tvStudentName.setText(studentName);
drawPieChar(rootView, rootView.getContext(), titles, values);
Button addNote = (Button)rootView.findViewById(R.id.addNote);
addNote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinearLayout layout = new LinearLayout(getActivity());
layout.setOrientation(LinearLayout.VERTICAL);
final EditText edittext = new EditText(getActivity());
edittext.setHint("Enter your note");
final DatePicker dp = new DatePicker(getActivity());
layout.addView(edittext);
layout.addView(dp);
alert.setView(layout);
alert.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
TextView tvNote = (TextView) rootView.findViewById(R.id.tvNote);
note = edittext.getText().toString();
String date = (dp.getMonth()+1) + "/" + dp.getDayOfMonth() + "/" + dp.getYear();
tvNote.setText(date+"-"+note);
editor.putString("attNote-" + studentName, date + "-" + note);
editor.commit();
}
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});

alert.show();
}
});
}


public void drawPieChar(View rootView, Context context, String[] title, int[] value) {
// Color of each Pie Chart Section
// Color of each Pie Chart Sections
int[] colors = {Color.BLUE, Color.MAGENTA, Color.GREEN, Color.CYAN, Color.RED, Color.TRANSPARENT};

//Set up the percentage data
CategorySeries categorySeries = new CategorySeries("Draw Pie");
double sum=0;
for(int i=0;i<value.length;i++){
sum+=value[i];
}
for (int i = 0; i < title.length; i++) {
categorySeries.add(title[i]+" ("+(Math.round(value[i]/sum*100))+"%)", value[i]);
categorySeries.add(title[i]+": " + value[i] +" ("+(Math.round(value[i]/sum*100))+"%)\t\t\t\t\t", value[i]);
}
DefaultRenderer defaultRenderer = new DefaultRenderer();
defaultRenderer.setShowLegend(true);
Expand Down
86 changes: 26 additions & 60 deletions app/src/main/res/layout/fragment_teacher_attendance_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,75 +15,41 @@
android:orientation="vertical"
android:weightSum="1">

<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_weight="0.15">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="Attendance(s): " />

<TextView
android:id="@+id/ra_tvAttendance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight="10"
android:text="0 " />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="14"
android:layout_gravity="right"
android:layout_weight="0.0"
android:text="Absence(s): " />

<TextView
android:id="@+id/ra_tvAbsences"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="15"
android:text="0" />

</TableRow>

<TableRow
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_column="0"
android:textAppearance="?android:attr/textAppearanceLarge"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_span="15"
android:id="@+id/chart"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_span="15"
android:id="@+id/chart"
android:orientation="vertical"></LinearLayout>


</TableRow>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Notes"
android:id="@+id/addNote" />

</TableLayout>
<TableLayout
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
android:inputType="textMultiLine"
android:ems="10"
android:text="Notes:"
android:id="@+id/textView8" />

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/tvNote" />

</TableRow>

</TableLayout>
</LinearLayout>

0 comments on commit 3f7af25

Please sign in to comment.