Android Open Source - ProjectStudio Update Professor Fragment






From Project

Back to project page ProjectStudio.

License

The source code is released under:

Apache License

If you think the Android project ProjectStudio 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 fragments;
/*from   w ww  .j  av  a 2  s  . c  om*/
import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.uniutilproject.R;

import java.sql.SQLException;

import DB_Provider.ProfessorDataSource;
import model.Professor;

/**
 * Created by desmond on 10/03/14.
 */
public class UpdateProfessorFragment extends Fragment {

    private String professor_mail;
    private String professor_name;
    private String professor_course;
    private long professor_id;
    private Professor updated_professor;
    private EditText prof_name_text;
    private EditText prof_course_text;
    private EditText prof_mail_text;
    private TextView update_button;
    private TextView cancel_button;
    private DrawerLayout parent_drawer;
    private ProfessorDataSource professorDataSource;
    private String previous_prof_name;
    private String previous_prof_course;
    private String previous_prof_mail;
    private LinearLayout acbar_cancel_button;
    private LinearLayout acbar_save_button;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.update_prof_view, container, false);

        //OPEN DATABASE
        professorDataSource = new ProfessorDataSource(getActivity());
        try {
            professorDataSource.open();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        //TO PREVENT VIEWS FROM OVERLAYING EACH OTHER WHEN
        //KEYPAD IS CALLED, CALL THIS METHOD
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

        //DRAWER HAS TO BE DISABLED IN OTHER TO PREVENT CHILD FRAGMENTS FROM OVERLAYING PARENT FRAGMENT
        //parent_drawer = new DrawerLayout(this.getActivity());
        //parent_drawer.setId(0x1000);
        parent_drawer = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout);
        parent_drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

        //INFLATE VIEWS HERE
        prof_name_text = (EditText) view.findViewById(R.id.update_prof_name);
        prof_course_text = (EditText) view.findViewById(R.id.update_prof_course);
        prof_mail_text = (EditText) view.findViewById(R.id.update_prof_mail);
        //update_button = (TextView) view.findViewById(R.id.update_prof_updatebtn);
        //cancel_button = (TextView) view.findViewById(R.id.update_prof_cancelbtn);

        //GET DATA FROM SELECTED LIST ITEM IN CURSOR ADAPTER
        Bundle bundle = this.getArguments();
        previous_prof_name = bundle.getString("professor_name");
        previous_prof_course = bundle.getString("professor_course");
        previous_prof_mail = bundle.getString("professor_mail");
        professor_id = bundle.getLong("professor_id");

        //SET HINT OF EDIT TEXT TO PREVIOUS PROFESSOR VALUES
        prof_name_text.setHint(previous_prof_name);
        prof_course_text.setHint(previous_prof_course);
        prof_mail_text.setHint(previous_prof_mail);

        //PUT LISTENERS HERE
        //update_button.setOnClickListener(new UpdateListener());
        //cancel_button.setOnClickListener(new CancelListner());

        professorDataSource.close();

        return view;
    }

    private class UpdateListener implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            professor_name = prof_name_text.getText().toString();
            professor_mail = prof_mail_text.getText().toString();
            professor_course = prof_course_text.getText().toString();

            //UPDATE THE PROFESSOR WITH THE NEW DATA
            updated_professor = new Professor();
            updated_professor.setId(professor_id);
            updated_professor.setProfessor_name(professor_name);
            updated_professor.setProfessor_course(professor_course);
            updated_professor.setProfessor_mail(professor_mail);

            if (prof_name_text.getText().toString().equals("")) {
                updated_professor.setProfessor_name(previous_prof_name);
                /*
                prof_name_text.post(new Runnable() {

                    public void run() {
                        prof_name_text.requestFocusFromTouch();
                        InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                        lManager.showSoftInput(prof_name_text, 0);
                        toast_empty_field("NAME FIELD CANNOT BE EMPTY");
                    }
                });
                */

            }
            if (prof_course_text.getText().toString().equals("")) {
                updated_professor.setProfessor_course(previous_prof_course);
                /*
                prof_course_text.post(new Runnable() {
                    public void run() {
                        prof_course_text.requestFocusFromTouch();
                        InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                        lManager.showSoftInput(prof_course_text, 0);
                        toast_empty_field("COURSE FIELD CANNOT BE EMPTY");
                    }
                });
                */
            }
            if (prof_mail_text.getText().toString().equals("")) {
                updated_professor.setProfessor_mail(previous_prof_mail);
                /*
                prof_mail_text.post(new Runnable() {
                    public void run() {
                        prof_mail_text.requestFocusFromTouch();
                        InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                        lManager.showSoftInput(prof_mail_text, 0);
                        toast_empty_field("MAIL FIELD CANNOT BE EMPTY");
                    }
                });
                */
            }

            //Execute Update
            professorDataSource.updateProfessor(updated_professor);
            //Return to previous fragment
            getActivity().onBackPressed();
                /*
                c = dataSource.getAllProfessors();
                swapCursor(c);
                notifyDataSetChanged();
                dataSource.close();*/

        }
    }

    private class CancelListner implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            //GO BACK TO THE PREVIOUS FRAGMENT
            getActivity().onBackPressed();
        }
    }

    //PRINT CUSTOM TOAST MESSAGE FOR EDITTEXT
    public void toast_empty_field(String message) {
        Toast toast = Toast.makeText(getActivity(),
                message, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.RELATIVE_LAYOUT_DIRECTION | Gravity.CENTER_HORIZONTAL, 0, 0);
        toast.show();
    }

    //REGSITER THE FRAGMENT AS A CONTRIBUTOR TO THE OPTIONS MENU
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }


    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        //REMOVE THE THREE DOT ICON FROM THE ACTIONBAR, SINCE IT IS NOT NEEDED FOR NOW
        super.onPrepareOptionsMenu(menu);
        MenuItem item = menu.findItem(R.id.action_settings);
        item.setVisible(false);

        //INFLATE CUSTOM ACTIONBAR
        ActionBar ab = getActivity().getActionBar();
        ab.setDisplayShowTitleEnabled(false);
        ab.setDisplayShowCustomEnabled(true);
        ab.setDisplayShowHomeEnabled(false);
        View customActionView = getActivity().getLayoutInflater().inflate(R.layout.actionbar_custom_layout, null);
        ab.setCustomView(customActionView);

        //ADD A LISTENER TO THE VIEWS IN THE CUSTOM ACTION BAR LAYOUT
        acbar_cancel_button = (LinearLayout) customActionView.findViewById(R.id.custom_ab_cancel);
        acbar_save_button = (LinearLayout) customActionView.findViewById(R.id.custom_ab_done);

        acbar_cancel_button.setOnClickListener(new CancelListner());
        acbar_save_button.setOnClickListener(new UpdateListener());

    }

}




Java Source Code List

DB_Provider.CourseDataSource.java
DB_Provider.DBManager.java
DB_Provider.DB_ABSTRACTS.java
DB_Provider.ProfessorDataSource.java
DB_Provider.TaskDataSource.java
Drawables.DrawableAlignedButton.java
FontPackage.TypefaceSpan.java
adapters.CourseCardAdapter.java
adapters.ExamsPassedCardAdapter.java
adapters.ExamsPendingCardAdapter.java
adapters.Exams_TabsPagerAdapter.java
adapters.HomeCardAdapter.java
adapters.MatesCardAdapter.java
adapters.NavDrawerListAdapter.java
adapters.ProfessorCardAdapter.java
adapters.TaskCardAdapter.java
adapters.TasksTabPagerAdapter.java
com.example.uniutilproject.BuildConfig.java
com.example.uniutilproject.UniUtil_MainActivity.java
days_fragments.FridayTaskFragment.java
days_fragments.MondayTaskFragment.java
days_fragments.SaturdayTaskFragment.java
days_fragments.SundayTaskFragment.java
days_fragments.ThursdayTaskFragment.java
days_fragments.TuesdayTaskFragment.java
days_fragments.WednesdayTaskFragment.java
dialog_fragments.DatePickerDialogFragment.java
dialog_fragments.MatesDialogFragment.java
dialog_fragments.ProfessorsDialogFragment.java
dialog_fragments.TimePickerDialogFragment.java
fragments.AddCourseFragment.java
fragments.AddProfFragment.java
fragments.AddTaskFragment.java
fragments.CoursesFragment.java
fragments.CursorLoaderListFragment.java
fragments.ExamsFragment.java
fragments.ExamsPassedFragment.java
fragments.ExamsPendingFragment.java
fragments.HomeFragment.java
fragments.MatesFragment.java
fragments.ProfessorsFragment.java
fragments.StudyPlanFragment.java
fragments.TasksFragment.java
fragments.UpdateCourseFragment.java
fragments.UpdateProfessorFragment.java
interfaces.NoticeDialogListener.java
interfaces.package-info.java
model.Course.java
model.Days.java
model.MyParcelable.java
model.NavDrawerItem.java
model.Professor.java
model.Task.java