Android Open Source - iEtueri Main Activity






From Project

Back to project page iEtueri.

License

The source code is released under:

GNU General Public License

If you think the Android project iEtueri listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package navigationdrawer;
/*from   w  ww.ja v  a 2 s . co m*/
import schedule.CalendarManager;
import schedule.RefreshScheduleEventsData;
import subject.NewSubjectFragment;
import utility.OnBackPressed;
import utility.OnClickButtonXml;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.javils.ietueri.R;

import courses.CourseDetailFragment;

public class MainActivity extends Activity implements NavigationDrawerCallbacks {

  // Fragment managing the behaviors, interactions and presentation of the
  // navigation drawer.
  private NavigationDrawerFragment navigationDrawerFragment;
  private CharSequence title;

  private static OnClickButtonXml fragment;
  private static Fragment currentFragment;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    navigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(
        R.id.navigation_drawer);
    // Initialize navigation transactions
    navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    title = getTitle();

    new Thread(new RefreshScheduleEventsData(this)).start();
    CalendarManager.checkCalendarID(this);

    if (CalendarManager.ID == -1)
      CalendarManager.createCalendar(getApplicationContext());

  }

  @Override
  public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    Fragment newFragment = NavigationDrawerController.newInstance(position + 1);
    currentFragment = newFragment;
    if (newFragment instanceof OnClickButtonXml)
      MainActivity.fragment = (OnClickButtonXml) newFragment;
    fragmentManager.beginTransaction().replace(R.id.navigation_drawer_container, newFragment).commit();
  }

  public void onSectionAttached(int section) {

    // first, call onPrepareOptionsMenu() for reset the ActionBar
    invalidateOptionsMenu();

    switch (section) {
    case NavigationDrawerController.SECTION_NUMBER_TODAY:
      title = getString(R.string.title_today);
      break;
    case NavigationDrawerController.SECTION_NUMBER_SCHEDULE:
      title = getString(R.string.title_schedule);
      break;
    case NavigationDrawerController.SECTION_NUMBER_HOMEWORK:
      title = getString(R.string.title_homework);
      break;
    case NavigationDrawerController.SECTION_NUMBER_EXAMS:
      title = getString(R.string.title_exam);
      break;
    case NavigationDrawerController.SECTION_NUMBER_COURSES:
      title = getString(R.string.title_course);
      break;
    case NavigationDrawerController.SECTION_NUMBER_SUBJECTS:
      title = getString(R.string.title_subject);
      break;
    case NavigationDrawerController.SECTION_NUMBER_NEW_EVENT_TODAY:
      title = getString(R.string.title_today_new_event);
      break;
    case NavigationDrawerController.SECTION_NUMBER_NEW_COURSE:
      title = getString(R.string.title_course_new_course);
      break;
    case NavigationDrawerController.SECTION_NUMBER_DETAIL_COURSE:
      title = getString(R.string.title_course_detail_course);
      break;
    case NavigationDrawerController.SECTION_NUMBER_NEW_SUBJECT:
      title = getString(R.string.title_course_new_subject);
      break;
    case NavigationDrawerController.SECTION_NUMBER_DETAIL_SUBJECT:
      title = getString(R.string.title_subject_detail_subject);
      break;
    case NavigationDrawerController.SECTION_NUMBER_NEW_EXAM:
      title = getString(R.string.new_exam);
      break;
    case NavigationDrawerController.SECTION_NUMBER_NEW_HOMEWORK:
      title = getString(R.string.new_homework);
      break;
    }
  }

  @Override
  public void onBackPressed() {
    if (currentFragment instanceof OnBackPressed)
      ((OnBackPressed) currentFragment).onBackPressed();
    else
      super.onBackPressed();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Only show items in the action bar relevant to this screen if the
    // drawer is not showing.
    if (!navigationDrawerFragment.isDrawerOpen()) {
      // TODO: Add the menu of each section here.

      /** Today Menu */
      if (title.equals(getString(R.string.title_today)))
        getMenuInflater().inflate(R.menu.menu_today, menu);

      /** Schedule Menu */
      if (title.equals(getString(R.string.title_schedule)))
        getMenuInflater().inflate(R.menu.menu_schedule, menu);

      /** Courses Menu */
      if (title.equals(getString(R.string.title_course)))
        getMenuInflater().inflate(R.menu.menu_courses, menu);

      /** Detail Courses Menu */
      if (title.equals(getString(R.string.title_course_detail_course)))
        getMenuInflater().inflate(R.menu.menu_detail_course, menu);

      /** Homework menu */
      /*
       * if (title.equals(getString(R.string.title_homework)))
       * getMenuInflater().inflate(R.menu.menu_homework, menu);
       */

      /** Exams Menu */
      /*
       * if (title.equals(getString(R.string.title_exam)))
       * getMenuInflater().inflate(R.menu.menu_exams, menu);
       */

      ActionBar actionBar = getActionBar();
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
      actionBar.setDisplayShowTitleEnabled(true);
      actionBar.setTitle(title);

      return true;
    }
    return super.onCreateOptionsMenu(menu);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here.

    int id = item.getItemId();

    /** Today Menu */
    if (id == R.id.menu_today_menu_new || id == R.id.menu_schedule_menu_new) {
      FragmentManager fragmentManager = getFragmentManager();
      Fragment newFragment = NavigationDrawerController
          .newInstance(NavigationDrawerController.SECTION_NUMBER_NEW_EVENT_TODAY);
      currentFragment = newFragment;
      if (newFragment instanceof OnClickButtonXml)
        MainActivity.fragment = (OnClickButtonXml) newFragment;
      fragmentManager.beginTransaction().replace(R.id.navigation_drawer_container, newFragment).commit();

      return true;
    }

    /** Course Menu */
    if (id == R.id.menu_courses_menu_new) {
      FragmentManager fragmentManager = getFragmentManager();
      Fragment newFragment = NavigationDrawerController
          .newInstance(NavigationDrawerController.SECTION_NUMBER_NEW_COURSE);
      currentFragment = newFragment;
      if (newFragment instanceof OnClickButtonXml)
        MainActivity.fragment = (OnClickButtonXml) newFragment;
      fragmentManager.beginTransaction().replace(R.id.navigation_drawer_container, newFragment).commit();

      return true;
    }

    /** New Subject Menu */
    if (id == R.id.menu_detail_courses_menu_new) {
      FragmentManager fragmentManager = getFragmentManager();
      Fragment newFragment = NavigationDrawerController
          .newInstance(NavigationDrawerController.SECTION_NUMBER_NEW_SUBJECT);
      ((NewSubjectFragment) newFragment).setCourse(((CourseDetailFragment) currentFragment).getCourse());
      currentFragment = newFragment;
      if (newFragment instanceof OnClickButtonXml)
        MainActivity.fragment = (OnClickButtonXml) newFragment;
      fragmentManager.beginTransaction().replace(R.id.navigation_drawer_container, newFragment).commit();

      return true;
    }
    // TODO: In the future, add the posibility of add homework and exams in
    // the respective view's.
    /** Homework menu */
    if (id == R.id.menu_homework_new) {
      /*
       * FragmentManager fragmentManager = getFragmentManager(); Fragment
       * newFragment = NavigationDrawerController
       * .newInstance(NavigationDrawerController
       * .SECTION_NUMBER_NEW_HOMEWORK); currentFragment = newFragment; if
       * (newFragment instanceof OnClickButtonXml) MainActivity.fragment =
       * (OnClickButtonXml) newFragment;
       * fragmentManager.beginTransaction()
       * .replace(R.id.navigation_drawer_container, newFragment).commit();
       * 
       * return true;
       */
    }

    /** Exam menu */
    if (id == R.id.menu_exam_new) {
      /*
       * FragmentManager fragmentManager = getFragmentManager(); Fragment
       * newFragment = NavigationDrawerController
       * .newInstance(NavigationDrawerController.SECTION_NUMBER_NEW_EXAM);
       * currentFragment = newFragment; if (newFragment instanceof
       * OnClickButtonXml) MainActivity.fragment = (OnClickButtonXml)
       * newFragment; fragmentManager.beginTransaction().replace(R.id.
       * navigation_drawer_container, newFragment).commit();
       * 
       * return true;
       */
    }

    // TODO: Add handle action for each item in the action bar here.
    return super.onOptionsItemSelected(item);
  }

  public static void setOnClickFragment(Fragment fragment) {
    if (fragment instanceof OnClickButtonXml)
      MainActivity.fragment = (OnClickButtonXml) fragment;
  }

  public static void setCurrentFragment(Fragment fragment) {
    if (fragment != null)
      MainActivity.currentFragment = fragment;
  }

  public static Fragment getCurrentFragment() {
    return currentFragment;
  }

  public void onClickButton(View view) {
    if (fragment != null)
      fragment.onClickXml(view);
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (currentFragment != null)
      currentFragment.onActivityResult(requestCode, resultCode, data);
  }

}




Java Source Code List

courses.CourseDetailFragment.java
courses.Course.java
courses.CoursesAdapter.java
courses.CoursesFragment.java
courses.NewCourseFragment.java
exams.Exam.java
exams.ExamsAdapter.java
exams.ExamsFragment.java
exams.NewExamFragment.java
homework.HomeworkAdapter.java
homework.HomeworkFragment.java
homework.Homework.java
homework.NewHomeworkFragment.java
navigationdrawer.DrawerListAdapter.java
navigationdrawer.DrawerList.java
navigationdrawer.MainActivity.java
navigationdrawer.NavigationDrawerCallbacks.java
navigationdrawer.NavigationDrawerController.java
navigationdrawer.NavigationDrawerFragment.java
navigationdrawer.OpenBrowser.java
schedule.CalendarManager.java
schedule.Event.java
schedule.EventsManager.java
schedule.FindEvents.java
schedule.RefreshScheduleEventsData.java
schedule.ScheduleFragment.java
schedule.ScheduleTodayAdapter.java
subject.DetailSubjectFragment.java
subject.NewSubjectFragment.java
subject.SubjectFragment.java
subject.SubjectListAdapter.java
subject.Subject.java
today.NewEventRepetitionDialogFragment.java
today.NewEventTodayFragment.java
today.TodayFragment.java
utility.DatabaseContract.java
utility.DatabaseHelper.java
utility.DatePickerDialogFragment.java
utility.OnBackPressed.java
utility.OnClickButtonXml.java
utility.PriorityDialogFragment.java
utility.TimePickerDialogFragment.java