Android Open Source - ProjectStudio Professor Card Adapter






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 adapters;
/*from  www  .  j  a v a2 s  .  c  o  m*/
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.example.uniutilproject.R;

import java.sql.SQLException;

import DB_Provider.DB_ABSTRACTS;
import DB_Provider.ProfessorDataSource;
import fragments.UpdateProfessorFragment;

public class ProfessorCardAdapter extends CursorAdapter {

    private Context appContext;
    private ProfessorDataSource dataSource;
    private AlertDialog.Builder build;
    private Cursor c;
    private EditText p_course;
    private EditText pr_name;
    private EditText p_mail;
    private FragmentActivity frag_context;
    private ViewGroup parent_view;
    private View view;
    private View c_view;

    public ProfessorCardAdapter(Context context, Cursor c, boolean autoRequery, ViewGroup p_view) {
        super(context, c, autoRequery);
        appContext = context;
        dataSource = new ProfessorDataSource(context);
        frag_context = (FragmentActivity) context;
        parent_view = p_view;
        this.c = c;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        // when the view will be created for first time,
        // we need to tell the adapters, how each item will look
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        //Log.e("fragment", parent.getContext() + " getContext");
        //Log.e("fragment", parent.getParent() + " getParent");
        View retView = inflater.from(context).inflate(R.layout.professors_list_item, parent, false);
        //parent_view = parent;
        c_view = retView;
        return retView;
    }




    @Override
    public void bindView(View convertView, Context context, Cursor cursor) {
        // here we are setting our data
        // that means, take the data from the cursor and put it in views
        final ViewHolder view_handler = new ViewHolder();

        view_handler.professor_name = (TextView) convertView.findViewById(R.id.professor_card_pname);
        view_handler.course_name = (TextView) convertView.findViewById(R.id.professor_card_coursename);
        view_handler.email = (TextView) convertView.findViewById(R.id.professor_card_email);
        view_handler.delete_button = (TextView) convertView.findViewById(R.id.professor_delete_button);
        view_handler.update_button = (TextView) convertView.findViewById(R.id.professor_update_button);
        view_handler.update_button.setTag(view_handler.update_button);


        final long professor_id = cursor.getLong(cursor.getColumnIndex(DB_ABSTRACTS.DBProfessor.KEY_ID));
        final String p_name = cursor.getString(cursor.getColumnIndex(DB_ABSTRACTS.DBProfessor.NAME_COLUMN));

        view_handler.professor_name.setText(p_name);
        view_handler.course_name.setText(cursor.getString(cursor.getColumnIndex(DB_ABSTRACTS.DBProfessor.COURSE_COLUMN)));
        view_handler.email.setText(cursor.getString(cursor.getColumnIndex(DB_ABSTRACTS.DBProfessor.EMAIL_COLUMN)));

        view_handler.delete_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e("delete", "Delete Button Clicked");
                try {
                    dataSource.open();
                } catch (SQLException e) {
                    e.printStackTrace();
                }

                build = new AlertDialog.Builder(appContext);
                build.setTitle("Delete " + p_name + " ? ");
                build.setMessage("Do you really want to delete ?");
                build.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dataSource.deleteProfessor(professor_id);
                        Log.e("delete", p_name + " removed");
                        c = dataSource.getAllProfessors();
                        swapCursor(c);
                        notifyDataSetChanged();
                        dataSource.close();
                    }
                });

                build.setNegativeButton("No", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = build.create();
                alert.show();
            }
        });

        view_handler.update_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                FragmentManager fm = frag_context.getSupportFragmentManager();
                UpdateProfessorFragment frag = new UpdateProfessorFragment();
                FragmentTransaction transaction = fm.beginTransaction();

                /* Take the necessary data to the called fragment*/
                Bundle bundle = new Bundle();
                bundle.putString("professor_name", view_handler.professor_name.getText().toString());
                bundle.putLong("professor_id", professor_id);
                bundle.putString("professor_mail", view_handler.email.getText().toString());
                bundle.putString("professor_course", view_handler.course_name.getText().toString());
                Log.e("fragment", view_handler.professor_name.toString() + "  professor name ");
                frag.setArguments(bundle);

                // For a little polish, specify a transition animation
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                //transaction.replace(R.id.professors_fragment_container, frag).addToBackStack(null).commit();
                // Log.e("fragment", ((ViewGroup) parent_view.getParent()).getId() + " ");
                // Log.e("fragment", parent_view.getId() + " ");
                //View parent = (View)
                transaction.replace(parent_view.getId() , frag).addToBackStack(null).commit();

                /*
                try {
                    dataSource.open();
                } catch (SQLException e) {
                    e.printStackTrace();
                }

                build = new AlertDialog.Builder(appContext);
                build.setTitle("Update " + p_name + " ? ");
                //build.setMessage("Do you really want to delete ?");
                //Inflate a custom view
                LayoutInflater inflater = LayoutInflater.from(appContext);
                View update_view = inflater.inflate(R.layout.prof_update_view, null);
                build.setView(update_view);


                pr_name = (EditText) update_view.findViewById(R.id.professor_update_name);

                p_course = (EditText) update_view.findViewById(R.id.professor_update_course);
                //update_course = p_course.getText().toString();
                p_mail = (EditText) update_view.findViewById(R.id.professor_update_email);
                //update_mail = p_course.getText().toString();

                build.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {


                        if (pr_name.getText().toString().equals("")) {
                            Toast.makeText(appContext, "empty field", Toast.LENGTH_LONG).show();
                        } else if (p_course.getText().toString().equals("")) {
                            Toast.makeText(appContext, "empty field", Toast.LENGTH_LONG).show();
                        } else if (p_mail.getText().toString().equals("")){
                            Toast.makeText(appContext, "empty field", Toast.LENGTH_LONG).show();
                        } else {
                            Professor professor = new Professor();
                            professor.setId(professor_id);
                            professor.setProfessor_name(pr_name.getText().toString());
                            professor.setProfessor_course(p_course.getText().toString());
                            professor.setProfessor_mail(p_mail.getText().toString());
                            dataSource.updateProfessor(professor);
                            c = dataSource.getAllProfessors();
                            swapCursor(c);
                            notifyDataSetChanged();
                            dataSource.close();
                       }
                    }
                });


                build.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = build.create();
                alert.show();
                */
            }
        });
    }


    //Create a holder class to contain all the view to inflate
    private static class ViewHolder {
        TextView professor_name;
        TextView course_name;
        TextView email;
        TextView delete_button;
        TextView update_button;
    }

    private void showChildFragment() {
        FragmentManager fm = frag_context.getSupportFragmentManager();
        UpdateProfessorFragment frag = new UpdateProfessorFragment();
        FragmentTransaction transaction = fm.beginTransaction();

        // For a little polish, specify a transition animation
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        //transaction.replace(R.id.professors_fragment_container, frag).addToBackStack(null).commit();
        // Log.e("fragment", ((ViewGroup) parent_view.getParent()).getId() + " ");
        // Log.e("fragment", parent_view.getId() + " ");
        //View parent = (View)
       transaction.replace(parent_view.getId() , frag).addToBackStack(null).commit();
    }

}




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