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; //from w w w . j a v a 2 s .c o m import java.util.ArrayList; import java.util.List; import android.app.ActionBar; import android.app.Activity; import android.os.Bundle; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import com.llenguatges.digitalcampus.MyApplication; import com.llenguatges.digitalcampus.R; import com.llenguatges.digitalcampus.adapters.NewSubSyllabusAdapter; import com.llenguatges.digitalcampus.adapters.NewSubjectStudentAdapter; 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.StudentSubject; import com.llenguatges.digitalcampus.objects.Subject; import com.llenguatges.digitalcampus.objects.SubjectMatter; public class NewSubjectActivity extends Activity { private Button next; private Button back; private Subject newSubject; private StudentTable st; private List<Student> studentList; private List<String> syllabus; private MyApplication myApp; /** * Interface definition for a callback to be invoked when a view is clicked. */ private OnClickListener onClick = new OnClickListener() { private ListView listView; private NewSubjectStudentAdapter adapter; private Button insert; private NewSubSyllabusAdapter syllabusAdapter; /** * Called when a view has been clicked. */ public void onClick(View v) { ActionBar actionBar = getActionBar(); TextView tv; switch(v.getId()){ case R.id.new_sub_next_1: tv = (TextView) findViewById(R.id.new_sub_name); newSubject.name = tv.getText().toString(); tv = (TextView) findViewById(R.id.new_sub_desc); newSubject.description = tv.getText().toString(); setContentView(R.layout.new_subject_layout2); actionBar.setSubtitle("New subject 2/3"); actionBar.setDisplayHomeAsUpEnabled(true); loadView(); next = (Button) findViewById(R.id.new_sub_next_2); next.setOnClickListener(onClick); back = (Button) findViewById(R.id.new_sub_back_2); back.setOnClickListener(onClick); break; case R.id.new_sub_next_2: for(int i = 0; i < studentList.size();i++){ if((CheckBox)listView.getChildAt(i).findViewById(R.id.student_checkbox) != null){ CheckBox cBox=(CheckBox)listView.getChildAt(i).findViewById(R.id.student_checkbox); if(cBox.isChecked()){ Student stu = studentList.get(i); stu.setSelected(true); studentList.set(i, stu); }else{ Student stu = studentList.get(i); stu.setSelected(false); studentList.set(i, stu); } } } setContentView(R.layout.new_subject_layout3); actionBar.setSubtitle("New subject 3/3"); actionBar.setDisplayHomeAsUpEnabled(true); next = (Button) findViewById(R.id.new_sub_next_3); next.setOnClickListener(onClick); back = (Button) findViewById(R.id.new_sub_back_3); back.setOnClickListener(onClick); insert = (Button) findViewById(R.id.ns_insert); insert.setOnClickListener(onClick); setView(); break; case R.id.new_sub_back_2: for(int i = 0; i < studentList.size();i++){ if((CheckBox)listView.getChildAt(i).findViewById(R.id.student_checkbox) != null){ CheckBox cBox=(CheckBox)listView.getChildAt(i).findViewById(R.id.student_checkbox); if(cBox.isChecked()){ Student stu = studentList.get(i); stu.setSelected(true); studentList.set(i, stu); }else{ Student stu = studentList.get(i); stu.setSelected(false); studentList.set(i, stu); } } } setContentView(R.layout.new_subject_layout1); actionBar.setSubtitle("New subject 1/3"); actionBar.setDisplayHomeAsUpEnabled(true); tv = (TextView) findViewById(R.id.new_sub_name); tv.setText(newSubject.name); tv = (TextView) findViewById(R.id.new_sub_desc); tv.setText(newSubject.description); next = (Button) findViewById(R.id.new_sub_next_1); next.setOnClickListener(onClick); break; case R.id.new_sub_back_3: setContentView(R.layout.new_subject_layout2); actionBar.setSubtitle("New subject 2/3"); actionBar.setDisplayHomeAsUpEnabled(true); loadView(); next = (Button) findViewById(R.id.new_sub_next_2); next.setOnClickListener(onClick); back = (Button) findViewById(R.id.new_sub_back_2); back.setOnClickListener(onClick); break; case R.id.ns_insert: EditText et = (EditText) findViewById(R.id.ns_matter_insert); syllabus.add(et.getText().toString()); syllabusAdapter.notifyDataSetChanged(); break; case R.id.new_sub_next_3: insertToDB(); finish(); break; } } /** * Set Activity's view and initialize UI actions. */ private void setView() { listView = (ListView) findViewById(R.id.ns_syllabus_lv); syllabusAdapter = new NewSubSyllabusAdapter(getApplicationContext(), syllabus); listView.setAdapter(syllabusAdapter); } /** * Load Activity's view and initialize UI actions. */ private void loadView() { listView = (ListView) findViewById(R.id.ns_studentsList); adapter = new NewSubjectStudentAdapter(getApplicationContext(), studentList); listView.setAdapter(adapter); } }; /** * 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); setContentView(R.layout.new_subject_layout1); myApp = (MyApplication) getApplication(); ActionBar actionBar = getActionBar(); actionBar.setSubtitle("New subject 1/3"); actionBar.setDisplayHomeAsUpEnabled(true); associateControls(); syllabus = new ArrayList<String>(); studentList = new ArrayList<Student>(); st = new StudentTable(getApplicationContext()); newSubject = new Subject(); studentList = st.GetDataFromTable(); } /** * Initialize UI Buttons for interacting with views. */ private void associateControls() { next = (Button) findViewById(R.id.new_sub_next_1); next.setOnClickListener(onClick); } /** * 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; default: return super.onOptionsItemSelected(item); } } /** * Inserts information into the specific tables related to the Activity. */ public void insertToDB(){ long subjectID; SubjectMatter submtt = new SubjectMatter(); StudentSubject stuSub = new StudentSubject(); StudentSubjectTable stsbTable = new StudentSubjectTable(getApplicationContext()); SubjectMatterTable smTable = new SubjectMatterTable(getApplicationContext()); SubjectTable subTable = new SubjectTable(getApplicationContext()); subjectID = subTable.Insert(newSubject); newSubject.id = subjectID; myApp.addSubject(newSubject); for (int i = 0; i < syllabus.size(); i++){ submtt.name = syllabus.get(i); submtt.position = i+1; submtt.subID = subjectID; smTable.Insert(submtt); } for (int i = 0; i < studentList.size(); i++){ if(studentList.get(i).getSelected()){ stuSub.subID = subjectID; stuSub.stuID = studentList.get(i).getId(); stsbTable.Insert(stuSub); } } } }