Back to project page digitalcampus.
The source code is released under:
MIT License
If you think the Android project digitalcampus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.llenguatges.digitalcampus.subjects; /*ww w .j a v a 2 s .co m*/ import java.util.ArrayList; import java.util.List; import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.ListView; import android.widget.TextView; import com.llenguatges.digitalcampus.R; import com.llenguatges.digitalcampus.adapters.SubjectStudentsAdapter; import com.llenguatges.digitalcampus.adapters.SyllabusAdapter; import com.llenguatges.digitalcampus.database.ExamTable; import com.llenguatges.digitalcampus.database.StudentSubjectTable; import com.llenguatges.digitalcampus.database.StudentTable; import com.llenguatges.digitalcampus.database.SubjectMatterTable; import com.llenguatges.digitalcampus.database.SubjectTable; import com.llenguatges.digitalcampus.objects.Student; import com.llenguatges.digitalcampus.objects.Subject; import com.llenguatges.digitalcampus.objects.SubjectMatter; public class InformationActivity extends Activity { private Subject subject; private List<Student> studentList; private List<Long> studentIdList; private List<SubjectMatter> syllabusArray; private StudentTable st; private StudentSubjectTable sst; private Long id; private SubjectStudentsAdapter adapter; private SyllabusAdapter syllabusAdapter; private ListView listView; private ListView syllabusListView; /** * Called when the activity is first created. * This is where you all of static set up: customize ActionBar. * This method also provides you with a Bundle containing the * activity's previously frozen state, if there was one. */ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); setContentView(R.layout.activity_subjects_info); id = extras.getLong("subject"); ActionBar acBar = getActionBar(); acBar.setSubtitle("Subject basic information"); acBar.setDisplayHomeAsUpEnabled(true); SubjectTable st = new SubjectTable(getApplicationContext()); subject = new Subject(); subject = st.GetSubjectById(id); setInfo(); setSyllabus(); setStudents(); } /** * Set subject's information text views */ private void setInfo() { TextView tv = (TextView) findViewById(R.id.subjectName); tv.setText(subject.name); tv = (TextView) findViewById(R.id.subjectDescription); tv.setText(subject.description); } /** * Set subject's name text view * @param name */ public void setSubjectName(String name) { TextView subjectName = (TextView)findViewById(R.id.subjectName); subjectName.setText(name); } /** * Set subject's description text view * @param description */ public void setSubjectDescription(String description) { TextView subjectDescription = (TextView)findViewById(R.id.subjectDescription); subjectDescription.setText(description); } /** * Set subject's syllabus list view */ public void setSyllabus() { syllabusArray = new ArrayList<SubjectMatter>(); SubjectMatterTable smT = new SubjectMatterTable(getApplicationContext()); syllabusArray = smT.GetDataFromTableBySubjectId(subject.id); syllabusAdapter = new SyllabusAdapter(getApplicationContext(), syllabusArray); syllabusListView = (ListView)findViewById(R.id.subjectListView); syllabusListView.setAdapter(syllabusAdapter); } /** * Set subject's students list view */ private void setStudents() { studentList = new ArrayList<Student>(); studentIdList = new ArrayList<Long>(); st = new StudentTable(getApplicationContext()); sst = new StudentSubjectTable(getApplicationContext()); studentIdList = sst.GetStudentIdFromTableBySubjectId(id); for(int i = 0; i < studentIdList.size(); i++){ studentList.add(st.GetStudentById(studentIdList.get(i))); } adapter = new SubjectStudentsAdapter(getApplicationContext(), studentList); listView = (ListView) findViewById(R.id.studentsListView); listView.setAdapter(adapter); } /** * This hook is called whenever an item in your options menu is selected. */ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; case R.id.menu_delete_subject: AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle("Delete"); alertDialogBuilder.setMessage("Delete "+subject.name+"?").setCancelable(false) .setPositiveButton("Delete",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { SubjectTable st = new SubjectTable(getApplicationContext()); st.DeleteById(subject.id); deleteSubject(subject.id); dialog.cancel(); finish(); } }) .setNegativeButton("Cancel",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); return true; default: return super.onOptionsItemSelected(item); } } /** * Deletes subject's information by subject id * @param id */ public void deleteSubject(long id){ SubjectMatterTable subMttTable = new SubjectMatterTable(getApplicationContext()); subMttTable.DeleteBySubjectID(id); StudentSubjectTable stSbTable = new StudentSubjectTable(getApplicationContext()); stSbTable.DeleteBySubjectID(id); ExamTable examTable = new ExamTable(getApplicationContext()); examTable.DeleteBySubjectId(id); } /** * Initialize the contents of the Activity's standard options menu. */ public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.subject_info_menu, menu); return true; } }