public View getView(int position, View convertView, ViewGroup parent) {
    Entity item = elements.get(position);

    View v = null;

    if (null == convertView) {
      v = View.inflate(mContext, R.layout.row_icon, null);
    } else {
      v = convertView;
    }

    ImageView img = (ImageView) v.findViewById(R.id.img_icon);
    img.setImageBitmap(ImageUtils.getBitmapAvatar(item.getId(), Utils.AVATAR_LARGE));

    return v;
  }
Ejemplo n.º 2
0
  private void populateFields() {
    if (currentEntity.isUpdate()) {
      // Get all the info from the database and put everything in the correct field
      assignName.setText(currentEntity.getValue("title").toString());
      assignComment.setText(currentEntity.getValue("comment").toString());
      if (currentEntity.getInt("done") == 1) {
        isDone = true;
      } else {
        isDone = false;
      }
      done.setChecked(isDone);

      Calendar dueDate = Calendar.getInstance();
      dueDate.setTimeInMillis(currentEntity.getLong("due"));
      due.updateDate(
          dueDate.get(Calendar.YEAR),
          dueDate.get(Calendar.MONTH),
          dueDate.get(Calendar.DAY_OF_MONTH));
    }
  }
Ejemplo n.º 3
0
 private void populateFields() {
   if (currentEntity.isUpdate()) {
     int dayPos =
         getPositionOf(
             getResources().getStringArray(R.array.days_array),
             currentEntity.getValue("day").toString());
     daySpinner.setSelection(dayPos);
     classRoom.setText(currentEntity.getValue("room").toString());
     classStart.setCurrentHour(currentEntity.getInt("starttimehour"));
     classStart.setCurrentMinute(currentEntity.getInt("starttimeminute"));
     classEnd.setCurrentHour(currentEntity.getInt("endtimehour"));
     classEnd.setCurrentMinute(currentEntity.getInt("endtimeminute"));
   }
 }
Ejemplo n.º 4
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putLong(DataFramework.KEY_ID, currentEntity.getId());
 }
Ejemplo n.º 5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.agendaday);

    context = this;
    getSupportActionBar();

    // Start the database
    try {
      DataFramework.getInstance().open(this, "com.albertoelias.aplusplusgenda");
    } catch (Exception e) {
      e.printStackTrace();
    }

    settings = getSharedPreferences("com.albertoelias.aplusplusgenda", MODE_PRIVATE);
    version = settings.getString("version", "0");

    // Check if the user has just updated the app. If so, do some changes.
    if (!version.equalsIgnoreCase("072") && !version.equalsIgnoreCase("073")) {
      try {
        List<Entity> classesToUpdate = db.getEntityList("class");
        Iterator<Entity> iter = classesToUpdate.iterator();
        while (iter.hasNext()) {
          Entity ent = (Entity) iter.next();
          int newvalue = ent.getInt("day") - 2;
          if (newvalue == -1) newvalue = 6;
          ent.setValue("day", newvalue);
          ent.save();
        }

        // Set that the changes has been done and the user has the latest version.
        SharedPreferences.Editor edit = settings.edit();
        edit.putString("version", "072");
        edit.commit();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (!version.equalsIgnoreCase("073")) {
      try {
        ArrayList<Entity> dueHwToUpdate = db.getEntityList("homework");
        Iterator<Entity> iter2 = dueHwToUpdate.iterator();
        while (iter2.hasNext()) {
          Entity ent = (Entity) iter2.next();

          Calendar calendar = new GregorianCalendar();
          calendar.setTimeInMillis(ent.getLong("setDate"));
          calendar = cambiarAGMT(calendar);
          ent.setValue("setDate", calendar.getTimeInMillis());

          Calendar due = new GregorianCalendar();
          due.setTimeInMillis(ent.getLong("due"));
          due = cambiarAGMT(due);
          ent.setValue("due", due.getTimeInMillis());

          ent.save();
        }

        ArrayList<Entity> dueAssignToUpdate = db.getEntityList("assignment");
        Iterator<Entity> iter3 = dueAssignToUpdate.iterator();
        while (iter3.hasNext()) {
          Entity ent = (Entity) iter3.next();

          Calendar calendar = new GregorianCalendar();
          calendar.setTimeInMillis(ent.getLong("setDate"));
          calendar = cambiarAGMT(calendar);
          ent.setValue("setDate", calendar.getTimeInMillis());

          Calendar due = new GregorianCalendar();
          due.setTimeInMillis(ent.getLong("due"));
          due = cambiarAGMT(due);
          ent.setValue("due", due.getTimeInMillis());

          ent.save();
        }

        ArrayList<Entity> dueExamsToUpdate = db.getEntityList("exam");
        Iterator<Entity> iter4 = dueExamsToUpdate.iterator();
        while (iter4.hasNext()) {
          Entity ent = (Entity) iter4.next();

          Calendar calendar = new GregorianCalendar();
          calendar.setTimeInMillis(ent.getLong("setDate"));
          calendar = cambiarAGMT(calendar);
          ent.setValue("setDate", calendar.getTimeInMillis());

          Calendar due = new GregorianCalendar();
          due.setTimeInMillis(ent.getLong("due"));
          due = cambiarAGMT(due);
          ent.setValue("due", due.getTimeInMillis());

          ent.save();
        }

        ArrayList<Entity> termsToUpdate = db.getEntityList("term");
        Iterator<Entity> iter5 = termsToUpdate.iterator();
        while (iter5.hasNext()) {
          Entity ent = (Entity) iter5.next();

          Calendar start = new GregorianCalendar();
          start.setTimeInMillis(ent.getLong("start_date"));
          start = cambiarAGMT(start);
          ent.setValue("start_date", start.getTimeInMillis());

          Calendar end = new GregorianCalendar();
          end.setTimeInMillis(ent.getLong("end_date"));
          end = cambiarAGMT(end);
          ent.setValue("end_date", end.getTimeInMillis());

          ent.save();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      // Set that the changes has been done and the user has the latest version.
      SharedPreferences.Editor edit = settings.edit();
      edit.putString("version", "073");
      edit.commit();
    }

    String[] groupArray = getResources().getStringArray(R.array.parentGroup);
    groups = new ArrayList<String>(Arrays.asList(groupArray));

    todayDate = (TextView) findViewById(R.id.date);
    mListView = (ExpandableListView) findViewById(android.R.id.list);
    mListView.setEmptyView(findViewById(android.R.id.empty));
    mListView.setGroupIndicator(null);
    mListView.setOnGroupCollapseListener(
        new ExpandableListView.OnGroupCollapseListener() {

          @Override
          public void onGroupCollapse(int collapseIndex) {
            // Now allow groups to collapse
            fillList();
            mListView.expandGroup(collapseIndex);
          }
        });

    // Get the date of the day the user's viewing
    Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);
  }
Ejemplo n.º 6
0
    @Override
    public View getChildView(
        int groupPosition,
        int childPosition,
        boolean isLastChild,
        View convertView,
        ViewGroup parent) {
      final Entity ent = (Entity) getChild(groupPosition, childPosition);
      // Set an id depending on the table ent belongs to
      int entId;
      if (ent.getTable() == "homework") {
        entId = 1;
      } else if (ent.getTable() == "assignment") {
        entId = 2;
      } else if (ent.getTable() == "exam") {
        entId = 3;
      } else {
        entId = 4;
      }

      // Depending on the id, do something different. For the first three, the only bit that changes
      // is the string in the alertDialog and the activity
      // that's opened when you press the element on the list. I'll comment due homework list, the
      // other are the same.
      switch (entId) {
          // Due homework list
        case 1:
          convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null);
          try {
            Button title = (Button) convertView.findViewById(R.id.title);
            ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove);
            TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass);
            LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.linearLayout1);

            // When editing this element, get the date it was set, not the date you're viewing.
            final Calendar c = Calendar.getInstance();
            c.setTimeInMillis(ent.getLong("setDate"));

            // Set text
            title.setText("- " + ent.getString("title"));
            // If the homework is done, strike it through.
            if (ent.getInt("done") == 1) {
              title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
              layout.setBackgroundColor(getResources().getColor(R.color.grey));
            }
            title.setOnClickListener(
                new OnClickListener() {

                  // When the element's pressed, open AddHwDialog with all the necessary data to
                  // edit it.
                  public void onClick(View addexam) {
                    Intent i = new Intent(AgendaDay.this, AddHwDialog.class);
                    i.putExtra("homework_id", ent.getId());
                    i.putExtra("todayCalendar", c.getTimeInMillis());
                    startActivityForResult(i, ACTIVITY_EDIT);
                  }
                });

            remove.setOnClickListener(
                new OnClickListener() {

                  public void onClick(View removerecord) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this);
                    builder
                        .setMessage(R.string.sureHomework)
                        .setTitle(R.string.sureHomeworkTitle)
                        .setCancelable(true)
                        .setNegativeButton(
                            R.string.cancel,
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int arg1) {
                                dialog.cancel();
                              }
                            })
                        .setPositiveButton(
                            R.string.accept,
                            new DialogInterface.OnClickListener() {
                              // Remove the element.
                              public void onClick(DialogInterface dialog, int arg1) {
                                ent.delete();
                                fillList();
                              }
                            });
                    AlertDialog AD = builder.create();
                    AD.show();
                  }
                });

            // Get the subject this element is associated with...
            Entity classEnt = new Entity("class", ent.getLong("class_id"));
            Entity subject = new Entity("subject", classEnt.getLong("subject_id"));

            // ...to put it as the name that appears.
            dueclass.setText(subject.getString("title"));
          } catch (Exception e) {
            e.printStackTrace();
          }
          break;
          // Due assignment list
        case 2:
          convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null);
          try {
            Button title = (Button) convertView.findViewById(R.id.title);
            ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove);
            TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass);
            LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.linearLayout1);

            final Calendar c = Calendar.getInstance();
            c.setTimeInMillis(ent.getLong("setDate"));

            title.setText("- " + ent.getString("title"));
            if (ent.getInt("done") == 1) {
              title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
              layout.setBackgroundColor(getResources().getColor(R.color.grey));
            }
            title.setOnClickListener(
                new OnClickListener() {

                  public void onClick(View addexam) {
                    Intent i = new Intent(AgendaDay.this, AddAssignDialog.class);
                    i.putExtra("assign_id", ent.getId());
                    i.putExtra("todayCalendar", c.getTimeInMillis());
                    startActivityForResult(i, ACTIVITY_EDIT);
                  }
                });

            remove.setOnClickListener(
                new OnClickListener() {

                  public void onClick(View removerecord) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this);
                    builder
                        .setMessage(R.string.sureAssignment)
                        .setTitle(R.string.sureAssignmentTitle)
                        .setCancelable(true)
                        .setNegativeButton(
                            R.string.cancel,
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int arg1) {
                                dialog.cancel();
                              }
                            })
                        .setPositiveButton(
                            R.string.accept,
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int arg1) {
                                ent.delete();
                                fillList();
                              }
                            });
                    AlertDialog AD = builder.create();
                    AD.show();
                  }
                });

            Entity classEnt = new Entity("class", ent.getLong("class_id"));
            Entity subject = new Entity("subject", classEnt.getLong("subject_id"));

            dueclass.setText(subject.getString("title"));
          } catch (Exception e) {
            e.printStackTrace();
          }
          break;
          // Due exam list
        case 3:
          convertView = View.inflate(AgendaDay.this, R.layout.agendaday_dueitem, null);
          try {
            Button title = (Button) convertView.findViewById(R.id.title);
            ImageView remove = (ImageView) convertView.findViewById(R.id.dueremove);
            TextView dueclass = (TextView) convertView.findViewById(R.id.dueclass);

            final Calendar c = Calendar.getInstance();
            c.setTimeInMillis(ent.getLong("setDate"));

            title.setText("- " + ent.getString("title"));
            title.setOnClickListener(
                new OnClickListener() {

                  public void onClick(View addexam) {
                    Intent i = new Intent(AgendaDay.this, AddExamDialog.class);
                    i.putExtra("exam_id", ent.getId());
                    i.putExtra("todayCalendar", c.getTimeInMillis());
                    startActivityForResult(i, ACTIVITY_EDIT);
                  }
                });

            remove.setOnClickListener(
                new OnClickListener() {

                  public void onClick(View removerecord) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this);
                    builder
                        .setMessage(R.string.sureExam)
                        .setTitle(R.string.sureExamTitle)
                        .setCancelable(true)
                        .setNegativeButton(
                            R.string.cancel,
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int arg1) {
                                dialog.cancel();
                              }
                            })
                        .setPositiveButton(
                            R.string.accept,
                            new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int arg1) {
                                ent.delete();
                                fillList();
                              }
                            });
                    AlertDialog AD = builder.create();
                    AD.show();
                  }
                });

            Entity classEnt = new Entity("class", ent.getLong("class_id"));
            Entity subject = new Entity("subject", classEnt.getLong("subject_id"));

            dueclass.setText(subject.getString("title"));
          } catch (Exception e) {
            e.printStackTrace();
          }
          break;
          // Today's classes list
        case 4:
          convertView = View.inflate(AgendaDay.this, R.layout.agendaday_item, null);
          try {
            Long subjectid = (Long) ent.getValue("subject_id");
            Entity subjectent = new Entity("subject", subjectid);

            // Get when the class starts and when it ends to...
            String starttimehour = ent.getString("starttimehour");
            // Add a 0 if it's lower than 10, Java doesn't do it automatically.
            if (Integer.parseInt(starttimehour) < 10) {
              starttimehour = "0" + starttimehour;
            }
            String starttimeminute = ent.getString("starttimeminute");
            if (Integer.parseInt(starttimeminute) < 10) {
              starttimeminute = "0" + starttimeminute;
            }
            String endtimehour = ent.getString("endtimehour");
            if (Integer.parseInt(endtimehour) < 10) {
              endtimehour = "0" + endtimehour;
            }
            String endtimeminute = ent.getString("endtimeminute");
            if (Integer.parseInt(endtimeminute) < 10) {
              endtimeminute = "0" + endtimeminute;
            }

            // ...display it nicely in a TextView
            String classLength =
                " ("
                    + starttimehour
                    + ":"
                    + starttimeminute
                    + "-"
                    + endtimehour
                    + ":"
                    + endtimeminute
                    + ")";

            TextView subject = (TextView) convertView.findViewById(R.id.subjectname);
            TextView classLengthText = (TextView) convertView.findViewById(R.id.classlength);
            subject.setText(subjectent.getString("title"));
            classLengthText.setText(classLength);

            LinearLayout hwlist =
                (LinearLayout) convertView.findViewById(R.id.homeworkLinearLayout);
            LinearLayout assignlist =
                (LinearLayout) convertView.findViewById(R.id.assignmentLinearLayout);
            LinearLayout examlist = (LinearLayout) convertView.findViewById(R.id.examLinearLayout);

            try {
              // Start my three arraylists.
              entHw = new ArrayList<Entity>();
              entExams = new ArrayList<Entity>();
              entAssignments = new ArrayList<Entity>();
              // Get today's date.
              Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
              c.set(mYear, mMonth, mDay, 0, 0, 0);
              c.set(Calendar.MILLISECOND, 0);

              // Get all homework associated to the class you're viewing.
              List<Entity> entclassHw =
                  db.getEntityList("homework", "class_id = '" + ent.getId() + "'");
              Iterator<Entity> iter = entclassHw.iterator();
              // Put in entHw only those that are set on the day you're viewing
              while (iter.hasNext()) {
                Entity HwEnt = (Entity) iter.next();
                Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                d.setTimeInMillis(HwEnt.getLong("setDate"));
                if (d.getTimeInMillis() == c.getTimeInMillis()) {
                  entHw.add(HwEnt);
                }
              }
              List<Entity> entclassAssignments =
                  db.getEntityList("assignment", "class_id = '" + ent.getId() + "'");
              Iterator<Entity> iter2 = entclassAssignments.iterator();
              while (iter2.hasNext()) {
                Entity AssignEnt = (Entity) iter2.next();
                Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                d.setTimeInMillis(AssignEnt.getLong("setDate"));
                if (d.get(Calendar.YEAR) == c.get(Calendar.YEAR)
                    && d.get(Calendar.DAY_OF_YEAR) == c.get(Calendar.DAY_OF_YEAR)) {
                  entAssignments.add(AssignEnt);
                }
              }
              List<Entity> entclassExams =
                  db.getEntityList("exam", "class_id = '" + ent.getId() + "'");
              Iterator<Entity> iter3 = entclassExams.iterator();
              while (iter3.hasNext()) {
                Entity ExamEnt = (Entity) iter3.next();
                Calendar d = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                d.setTimeInMillis(ExamEnt.getLong("setDate"));
                if (d.get(Calendar.YEAR) == c.get(Calendar.YEAR)
                    && d.get(Calendar.DAY_OF_YEAR) == c.get(Calendar.DAY_OF_YEAR)) {
                  entExams.add(ExamEnt);
                }
              }
            } catch (Exception e) {
              e.printStackTrace();
            }

            // Get a date for the day you're viewing
            final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
            c.set(mYear, mMonth, mDay, 0, 0, 0);
            c.set(Calendar.MILLISECOND, 0);

            // For every homework you have on the day your viewing and the class element the list is
            // at.
            for (final Entity ent2 : entHw) {
              LinearLayout linear = new LinearLayout(getApplicationContext());
              linear.setOrientation(LinearLayout.HORIZONTAL);
              LayoutParams linearLayoutParams =
                  new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
              linear.setLayoutParams(linearLayoutParams);
              linear.setBackgroundResource(R.color.purple);

              Button hwTitle = new Button(getApplicationContext());
              hwTitle.setText("- " + ent2.getString("title"));
              if (ent2.getInt("done") == 1) {
                hwTitle.setPaintFlags(hwTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
              }
              hwTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19);
              hwTitle.setGravity(Gravity.LEFT);
              hwTitle.setPadding(5, 5, 0, 5);
              LayoutParams titleButtonLayoutParams =
                  new LinearLayout.LayoutParams(
                      LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1);
              hwTitle.setLayoutParams(titleButtonLayoutParams);
              hwTitle.setBackgroundColor(android.R.color.transparent);

              hwTitle.setOnClickListener(
                  new OnClickListener() {

                    public void onClick(View addexam) {
                      Intent i = new Intent(AgendaDay.this, AddHwDialog.class);
                      i.putExtra("homework_id", ent2.getId());
                      i.putExtra("todayCalendar", c.getTimeInMillis());
                      startActivityForResult(i, ACTIVITY_EDIT);
                    }
                  });

              ImageView remove = new ImageView(getApplicationContext());
              LayoutParams removeButtonLayoutParams =
                  new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
              removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL;
              remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove));
              remove.setLayoutParams(removeButtonLayoutParams);

              remove.setOnClickListener(
                  new OnClickListener() {

                    public void onClick(View removerecord) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this);
                      builder
                          .setMessage(R.string.sureHomework)
                          .setTitle(R.string.sureHomeworkTitle)
                          .setCancelable(true)
                          .setNegativeButton(
                              R.string.cancel,
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int arg1) {
                                  dialog.cancel();
                                }
                              })
                          .setPositiveButton(
                              R.string.accept,
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int arg1) {
                                  ent2.delete();
                                  fillList();
                                }
                              });
                      AlertDialog AD = builder.create();
                      AD.show();
                    }
                  });

              linear.addView(hwTitle);
              linear.addView(remove);
              hwlist.addView(linear);
            }

            for (final Entity ent2 : entAssignments) {
              LinearLayout linear = new LinearLayout(getApplicationContext());
              linear.setOrientation(LinearLayout.HORIZONTAL);
              LayoutParams linearLayoutParams =
                  new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
              linear.setLayoutParams(linearLayoutParams);
              linear.setBackgroundResource(R.color.light_green);

              Button assignTitle = new Button(getApplicationContext());
              assignTitle.setText("- " + ent2.getString("title"));
              if (ent2.getInt("done") == 1) {
                assignTitle.setPaintFlags(
                    assignTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
              }
              assignTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
              assignTitle.setGravity(Gravity.LEFT);
              assignTitle.setPadding(5, 5, 0, 5);
              LayoutParams titleButtonLayoutParams =
                  new LinearLayout.LayoutParams(
                      LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1);
              assignTitle.setLayoutParams(titleButtonLayoutParams);
              assignTitle.setBackgroundColor(android.R.color.transparent);

              assignTitle.setOnClickListener(
                  new OnClickListener() {

                    public void onClick(View addexam) {
                      Intent i = new Intent(AgendaDay.this, AddAssignDialog.class);
                      i.putExtra("assign_id", ent2.getId());
                      i.putExtra("todayCalendar", c.getTimeInMillis());
                      startActivityForResult(i, ACTIVITY_EDIT);
                    }
                  });

              ImageView remove = new ImageView(getApplicationContext());
              LayoutParams removeButtonLayoutParams =
                  new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
              removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL;
              remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove));
              remove.setLayoutParams(removeButtonLayoutParams);

              remove.setOnClickListener(
                  new OnClickListener() {

                    public void onClick(View removerecord) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this);
                      builder
                          .setMessage(R.string.sureAssignment)
                          .setTitle(R.string.sureAssignmentTitle)
                          .setCancelable(true)
                          .setNegativeButton(
                              R.string.cancel,
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int arg1) {
                                  dialog.cancel();
                                }
                              })
                          .setPositiveButton(
                              R.string.accept,
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int arg1) {
                                  ent2.delete();
                                  fillList();
                                }
                              });
                      AlertDialog AD = builder.create();
                      AD.show();
                    }
                  });

              linear.addView(assignTitle);
              linear.addView(remove);
              assignlist.addView(linear);
            }

            for (final Entity ent2 : entExams) {
              LinearLayout linear = new LinearLayout(getApplicationContext());
              linear.setOrientation(LinearLayout.HORIZONTAL);
              LayoutParams linearLayoutParams =
                  new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
              linear.setLayoutParams(linearLayoutParams);
              linear.setBackgroundResource(R.color.light_orange);

              Button examTitle = new Button(getApplicationContext());
              examTitle.setText("- " + ent2.getString("title"));
              examTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
              examTitle.setGravity(Gravity.LEFT);
              examTitle.setPadding(5, 5, 0, 5);
              LayoutParams titleButtonLayoutParams =
                  new LinearLayout.LayoutParams(
                      LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1);
              examTitle.setLayoutParams(titleButtonLayoutParams);
              examTitle.setBackgroundColor(android.R.color.transparent);

              examTitle.setOnClickListener(
                  new OnClickListener() {

                    public void onClick(View addexam) {
                      Intent i = new Intent(AgendaDay.this, AddExamDialog.class);
                      i.putExtra("exam_id", ent2.getId());
                      i.putExtra("todayCalendar", c.getTimeInMillis());
                      startActivityForResult(i, ACTIVITY_EDIT);
                    }
                  });

              ImageView remove = new ImageView(getApplicationContext());
              LayoutParams removeButtonLayoutParams =
                  new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
              removeButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL;
              remove.setBackgroundDrawable(getResources().getDrawable(R.drawable.remove));
              remove.setLayoutParams(removeButtonLayoutParams);

              remove.setOnClickListener(
                  new OnClickListener() {

                    public void onClick(View removerecord) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(AgendaDay.this);
                      builder
                          .setMessage(R.string.sureExam)
                          .setTitle(R.string.sureExamTitle)
                          .setCancelable(true)
                          .setNegativeButton(
                              R.string.cancel,
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int arg1) {
                                  dialog.cancel();
                                }
                              })
                          .setPositiveButton(
                              R.string.accept,
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int arg1) {
                                  ent2.delete();
                                  fillList();
                                }
                              });
                      AlertDialog AD = builder.create();
                      AD.show();
                    }
                  });

              linear.addView(examTitle);
              linear.addView(remove);
              examlist.addView(linear);
            }

            ImageView add = (ImageView) convertView.findViewById(R.id.add);

            add.setOnClickListener(
                new OnClickListener() {
                  public void onClick(View addsubject) {
                    Intent i = new Intent(AgendaDay.this, AddAssignmentListDialog.class);
                    i.putExtra("class_id", ent.getId());
                    Calendar c = Calendar.getInstance();
                    c.set(mYear, mMonth, mDay, 0, 0, 0);
                    c.set(Calendar.MILLISECOND, 0);
                    c.setTimeZone(TimeZone.getTimeZone("GMT"));
                    i.putExtra("todayCalendar", c.getTimeInMillis());
                    startActivityForResult(i, ACTIVITY_CREATE);
                  }
                });
          } catch (Exception e) {
            e.printStackTrace();
          }
          break;
      }
      return convertView;
    }