Ejemplo n.º 1
0
  public void searchNotifications() {

    List<Entity> searchs = DataFramework.getInstance().getEntityList("search");

    for (int i = 0; i < searchs.size(); i++) {
      if (searchs.get(i).getInt("notifications") == 1
          && !PreferenceUtils.getStatusWorkApp(context)) {
        EntitySearch es = new EntitySearch(searchs.get(i).getId());

        if (type != OnAlarmReceiver.ALARM_ONLY_OTHERS) {
          InfoSaveTweets info = es.saveTweets(context, true, -1);
          if (info.getNewMessages() > 0 && searchs.get(i).getInt("notifications_bar") == 1) {
            showSearchNotifications = true;
          }
        }

        int count = es.getValueNewCount();

        totalSearchesAWD += count;

        if (searchs.get(i).getInt("notifications_bar") == 1) {
          SearchNotifications sn = new SearchNotifications();
          sn.setTotal(count);
          sn.setName(searchs.get(i).getString("name"));
          mSearchNotifications.add(sn);
        }
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  protected Void doInBackground(Void... args) {
    try {
      DataFramework.getInstance().open(context, Utils.packageName);
    } catch (Exception e) {
      e.printStackTrace();
    }

    ConnectionManager.getInstance().open(context);

    twitter = ConnectionManager.getInstance().getUserForSearchesTwitter();

    PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
    preferences = PreferenceManager.getDefaultSharedPreferences(context);

    try {
      if (!PreferenceUtils.getStatusWorkApp(context)) {
        searchUser();
      }
      if (!PreferenceUtils.getStatusWorkApp(context)) {
        searchNotifications();
      }
      if (!PreferenceUtils.getStatusWorkApp(context)) {
        writeADWLauncher();
      }

      if (!PreferenceUtils.getStatusWorkApp(context)) {
        shouldSendNotificationAndroid();
      }
    } catch (Exception e) {
      e.printStackTrace();
      PreferenceUtils.saveStatusWorkAlarm(context, false);
    } finally {
      PreferenceUtils.saveStatusWorkAlarm(context, false);
    }

    DataFramework.getInstance().close();

    PreferenceUtils.saveStatusWorkAlarm(context, false);

    WidgetCounters2x1.updateAll(context);
    WidgetCounters4x1.updateAll(context);

    Log.d(Utils.TAG_ALARM, "Finalizado notificaciones en background");

    return null;
  }
Ejemplo n.º 3
0
  /* (non-Javadoc)
   * @see android.app.Activity#onCreate()
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialize database
    try {
      db = DataFramework.getInstance();
      db.open(this, this.getPackageName());
      dbHelper = new DataBaseHelper(db);

    } catch (Exception ex) {
      Log.e(ex.getClass().getSimpleName(), ex.getMessage());
      error(ex.getMessage());
      ex.printStackTrace();
    }
  }
Ejemplo n.º 4
0
public class NewSubjectClass extends Activity {

  private EditText classRoom;
  private Spinner daySpinner;
  private TimePicker classStart;
  private TimePicker classEnd;

  private Entity currentEntity;
  private String subjectId;
  private DataFramework db = DataFramework.getInstance();

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newsubject_newclass);
    getWindow()
        .setLayout(LayoutParams.FILL_PARENT /* width */, LayoutParams.WRAP_CONTENT /* height */);

    classRoom = (EditText) findViewById(R.id.room);
    classStart = (TimePicker) findViewById(R.id.timePicker1);
    classStart.setIs24HourView(true);
    classEnd = (TimePicker) findViewById(R.id.timePicker2);
    classEnd.setIs24HourView(true);

    try {
      db.open(this, "com.albertoelias.agenda");
    } catch (Exception e) {
      e.printStackTrace();
    }

    daySpinner = (Spinner) findViewById(R.id.daySpinner);
    ArrayAdapter<CharSequence> adapter =
        ArrayAdapter.createFromResource(
            this, R.array.days_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    daySpinner.setAdapter(adapter);

    Button Cancel = (Button) findViewById(R.id.cancel);
    Button Submit = (Button) findViewById(R.id.submit);

    long mRowId =
        savedInstanceState != null ? savedInstanceState.getLong(DataFramework.KEY_ID) : -1;
    if (mRowId < 0) {
      Bundle extras = getIntent().getExtras();
      if (extras.containsKey("SubjectID")) {
        this.subjectId = extras.getString("SubjectID");
        currentEntity = new Entity("date");
      } else {
        mRowId = extras != null ? extras.getLong(DataFramework.KEY_ID) : -1;
        currentEntity = new Entity("date", mRowId);
        populateFields();
      }
    }

    Submit.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            int daynumber = daySpinner.getSelectedItemPosition() + 2;
            if (daynumber == 8) {
              daynumber = 1;
            }
            currentEntity.setValue("day", daynumber);
            currentEntity.setValue("room", classRoom.getText().toString());
            currentEntity.setValue("starttimehour", classStart.getCurrentHour());
            currentEntity.setValue("starttimeminute", classStart.getCurrentMinute());
            currentEntity.setValue("endtimehour", classEnd.getCurrentHour());
            currentEntity.setValue("endtimeminute", classEnd.getCurrentMinute());
            // Para cuando funcione el pulsar en un elemento de la lista
            if (subjectId != null) {
              currentEntity.setValue("subject_id", subjectId);
            }
            currentEntity.save();
            setResult(RESULT_OK);
            finish();
          }
        });

    Cancel.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View cancel) {
            setResult(RESULT_CANCELED);
            finish();
          }
        });
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    db.close();
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putLong(DataFramework.KEY_ID, currentEntity.getId());
  }

  @Override
  protected void onResume() {
    super.onResume();
    populateFields();
  }

  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"));
    }
  }

  private int getPositionOf(String[] array, String element) {
    int res = -1;
    for (int i = 0; i < array.length; i++) {
      if (array[i].equalsIgnoreCase(element)) {
        res = i;
        break;
      }
    }
    return res;
  }
}
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
public class AgendaDay extends FragmentActivity {

  private static final int ACTIVITY_CREATE = 0;
  private static final int ACTIVITY_EDIT = 1;

  static final int DATE_DIALOG_ID = 0;

  private Context context;

  private ExpandableListView mListView;
  private TextView todayDate;

  private ArrayList<String> groups;
  private ArrayList<ArrayList<Entity>> children;

  private ArrayList<Entity> classes;
  private ArrayList<Entity> dueHw;
  private ArrayList<Entity> dueExams;
  private ArrayList<Entity> dueAssignments;

  private List<Entity> entHw;
  private List<Entity> entExams;
  private List<Entity> entAssignments;

  private int mYear;
  private int mMonth;
  private int mDay;

  private DataFramework db = DataFramework.getInstance();
  SharedPreferences settings;
  String version;

  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
  }

  @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);
  }

  public static Calendar cambiarAGMT(Calendar cale) {

    Date fecha = cale.getTime();
    TimeZone timeZ = cale.getTimeZone();

    // Obtenemos los milisegundos de diferencia con respecto a la fecha en UTC
    long miliSeg = fecha.getTime();

    // Obtenemos la diferencia con respecto a la fecha actual
    int diff = timeZ.getOffset(miliSeg);

    // Creamos un nuevo calendario GMT zona horaria, con los cambios anteriores
    Calendar nuevoCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    nuevoCal.setTime(fecha);
    nuevoCal.add(Calendar.MILLISECOND, diff);

    return nuevoCal;
  }

  private class AgendaSubjectsAdapter extends BaseExpandableListAdapter {

    @Override
    public Object getChild(int groupPosition, int childPosition) {
      return children.get(groupPosition).get(childPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
      return childPosition;
    }

    @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;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
      return children.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
      return groups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
      return groups.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
      return groupPosition;
    }

    @Override
    public View getGroupView(
        int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
      // Show the group list of the expandable listview (Homework, Assignment, Exams and Classes)
      String groupTitle = (String) getGroup(groupPosition);
      if (convertView == null) {
        LayoutInflater infalInflater =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.agendaday_group_item, null);
      }
      TextView title = (TextView) convertView.findViewById(R.id.groupTitle);
      title.setText(groupTitle);
      return convertView;
    }

    @Override
    public boolean hasStableIds() {
      return true;
    }

    @Override
    public boolean isChildSelectable(int arg0, int arg1) {
      return true;
    }
  }

  private void fillList() {
    try {
      // Sets the calendar for today without considering time, only the date is important. I also
      // set a default timezone, the timezone isn't important
      // so I set a default one so when you change the timezone on your phone, all your things will
      // still appear.
      Calendar calendar = Calendar.getInstance();
      calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
      calendar.set(mYear, mMonth, mDay, 0, 0, 0);
      calendar.set(Calendar.MILLISECOND, 0);

      // Parse the date to show it nicely
      SimpleDateFormat formatFecha = new SimpleDateFormat("EEEE dd/MM/yyyy");
      String fParseada = formatFecha.format(calendar.getTime());
      todayDate.setText(fParseada);

      int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 2;
      if (dayOfWeek == -1) dayOfWeek = 6;

      // Get all the lists of stuff from the database and put them all together to pass them to the
      // adapter
      classes =
          db.getEntityList(
              "class", "day = '" + String.valueOf(dayOfWeek) + "'", "starttimehour asc");
      dueHw =
          db.getEntityList(
              "homework", "due = '" + String.valueOf(calendar.getTimeInMillis()) + "'", "done asc");
      dueAssignments =
          db.getEntityList(
              "assignment",
              "due = '" + String.valueOf(calendar.getTimeInMillis()) + "'",
              "done asc");
      dueExams =
          db.getEntityList("exam", "due = '" + String.valueOf(calendar.getTimeInMillis()) + "'");
      children = new ArrayList<ArrayList<Entity>>();
      children.add(dueHw);
      children.add(dueAssignments);
      children.add(dueExams);
      children.add(classes);
      mListView.setAdapter(new AgendaSubjectsAdapter());
      // Expand every group so make everything look like a unified list
      for (int x = 0; x < groups.size(); x++) {
        mListView.expandGroup(x);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  @Override
  protected void onResume() {
    super.onResume();
    try {
      fillList();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    db.close();
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent i) {
    super.onActivityResult(requestCode, resultCode, i);
    fillList();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.homemenu, menu);
    return super.onCreateOptionsMenu(menu);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.subjects:
        Intent intentsubjects = new Intent(this, SubjectList.class);
        startActivity(intentsubjects);
        break;
      case R.id.gotoday:
        showDialog(DATE_DIALOG_ID);
        break;
      case R.id.timetable:
        Intent openTimetable = new Intent(this, WeekTimetable.class);
        startActivity(openTimetable);
        break;
      case R.id.examlist:
        Intent openExamList = new Intent(this, ExamList.class);
        startActivity(openExamList);
        break;
      case R.id.settings:
        Intent openSettings = new Intent(this, Settings.class);
        startActivity(openSettings);
        break;
    }

    return super.onOptionsItemSelected(item);
  }

  private DatePickerDialog.OnDateSetListener mDateSetListener =
      new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
          // Get the date the user entered in the dialog
          mYear = year;
          mMonth = monthOfYear;
          mDay = dayOfMonth;
          fillList();
        }
      };

  @Override
  protected Dialog onCreateDialog(int id) {
    // Sets the date on the dialog with the day you're viewing in that moment
    switch (id) {
      case DATE_DIALOG_ID:
        int dialogYear = mYear;
        int dialogMonth = mMonth;
        int dialogDay = mDay;
        return new DatePickerDialog(
            this,
            R.style.Theme_DatePickerDialog,
            mDateSetListener,
            dialogYear,
            dialogMonth,
            dialogDay);
    }
    return null;
  }
}
Ejemplo n.º 7
0
public class AddAssignDialog extends Activity {

  private DataFramework db = DataFramework.getInstance();

  private EditText assignName;
  private EditText assignComment;
  private DatePicker due;
  private CheckBox done;

  private Entity currentEntity;
  private Long classId;
  private Long mRowId;
  private Boolean isDone;

  private Calendar date = Calendar.getInstance();

  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addassigndialog);

    getWindow()
        .setLayout(LayoutParams.FILL_PARENT /* width */, LayoutParams.WRAP_CONTENT /* height */);

    assignName = (EditText) findViewById(R.id.assignName);
    assignComment = (EditText) findViewById(R.id.assignComment);
    due = (DatePicker) findViewById(R.id.due);
    done = (CheckBox) findViewById(R.id.done);

    try {
      db.open(this, "com.albertoelias.aplusplusgenda");
    } catch (Exception e) {
      e.printStackTrace();
    }

    // Find out if the user is creating or editing
    mRowId = savedInstanceState != null ? savedInstanceState.getLong(DataFramework.KEY_ID) : -1;
    if (mRowId < 0) {
      // Get the day the user is viewing
      Bundle extras = getIntent().getExtras();
      Long milis = extras.getLong("todayCalendar");
      this.date.setTimeInMillis(milis);
      if (extras.containsKey("class_id")) {
        // Create a new assignment
        this.classId = extras.getLong("class_id");
        currentEntity = new Entity("assignment");
        // Set the due date to one day later.
        due.updateDate(
            date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH) + 1);
      } else {
        // Get the ID and open the assignment and populate the fields with the assignment's values
        mRowId = extras != null ? extras.getLong("assign_id") : -1;
        currentEntity = new Entity("assignment", mRowId);
        populateFields();
      }
    }

    // Mark the assignment as done
    done.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
              currentEntity.setValue("done", 1);
              isDone = true;
              currentEntity.save();
            } else {
              currentEntity.setValue("done", 0);
              currentEntity.save();
            }
          }
        });

    Button cancel = (Button) findViewById(R.id.cancel);
    cancel.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View cancel) {
            setResult(RESULT_CANCELED);
            finish();
          }
        });

    Button submit = (Button) findViewById(R.id.submit);
    submit.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View submit) {
            due.clearFocus();
            String assignTitle = assignName.getText().toString().trim();
            if (!assignTitle.equalsIgnoreCase("")) {
              int year = due.getYear();
              int month = due.getMonth();
              int day = due.getDayOfMonth();
              Calendar duedate = Calendar.getInstance();
              // Set everything to 0 because the only important part is the date
              duedate.set(year, month, day, 0, 0, 0);
              duedate.set(Calendar.MILLISECOND, 0);
              duedate.setTimeZone(TimeZone.getTimeZone("GMT"));
              // Check if the duedate is a valid date
              if (due.getYear() < date.get(Calendar.YEAR)
                  || due.getYear() > date.get(Calendar.YEAR) + 1
                  || duedate.getTimeInMillis() < date.getTimeInMillis()) {
                Toast.makeText(getApplicationContext(), R.string.notcorrectyear, Toast.LENGTH_LONG)
                    .show();
              } else {
                // Save everything
                currentEntity.setValue("title", assignName.getText().toString());
                currentEntity.setValue("comment", assignComment.getText().toString());
                currentEntity.setValue("due", duedate.getTimeInMillis());
                if (classId != null) {
                  currentEntity.setValue("setDate", date.getTimeInMillis());
                  currentEntity.setValue("class_id", classId);
                }
                currentEntity.save();
                setResult(RESULT_OK);
                finish();
              }
            } else {
              Toast.makeText(getApplicationContext(), R.string.noassignmessage, Toast.LENGTH_LONG)
                  .show();
            }
          }
        });
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    db.close();
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putLong(DataFramework.KEY_ID, currentEntity.getId());
  }

  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.º 8
0
  public void searchUser() {

    List<Entity> users =
        DataFramework.getInstance()
            .getEntityList("users", "service is null or service = \"twitter.com\"");

    boolean timeline = preferences.getBoolean("prf_notif_in_timeline", false);
    boolean mentions = preferences.getBoolean("prf_notif_in_mentions", true);
    boolean dms = preferences.getBoolean("prf_notif_in_direct", true);

    for (int i = 0; i < users.size(); i++) {
      try {

        if (!PreferenceUtils.getStatusWorkApp(context)) {
          loadUser(users.get(i).getId());
          Log.d(Utils.TAG_ALARM, "Cargar en background usuario " + twitter.getScreenName());
        }

        UserNotifications userNotification = new UserNotifications();

        userNotification.setName(users.get(i).getString("name"));
        userNotification.setId(users.get(i).getId());

        // TIMELINE

        if (TweetTopicsUtils.hasColumn(users.get(i).getId(), TweetTopicsUtils.COLUMN_TIMELINE)) {
          EntityTweetUser etuTimeline =
              new EntityTweetUser(users.get(i).getId(), TweetTopicsUtils.TWEET_TYPE_TIMELINE);
          if (!PreferenceUtils.getStatusWorkApp(context)
              && type != OnAlarmReceiver.ALARM_ONLY_OTHERS) {
            InfoSaveTweets info = etuTimeline.saveTweets(context, twitter);
            if (info.getNewMessages() > 0 && timeline) {
              userNotification.setIdsTimeline(info.getIds());
            }
          }
          totalTimelineADW += etuTimeline.getValueNewCount();
        }

        // MENTIONS

        if (TweetTopicsUtils.hasColumn(users.get(i).getId(), TweetTopicsUtils.COLUMN_MENTIONS)) {
          EntityTweetUser etuMentions =
              new EntityTweetUser(users.get(i).getId(), TweetTopicsUtils.TWEET_TYPE_MENTIONS);
          if (!PreferenceUtils.getStatusWorkApp(context)
              && type != OnAlarmReceiver.ALARM_ONLY_TIMELINE) {
            InfoSaveTweets info = etuMentions.saveTweets(context, twitter);
            if (info.getNewMessages() > 0 && mentions) {
              userNotification.setIdsMentions(info.getIds());
            }
          }

          totalMentionsADW += etuMentions.getValueNewCount();
        }

        // DIRECTOS

        if (TweetTopicsUtils.hasColumn(
            users.get(i).getId(), TweetTopicsUtils.COLUMN_DIRECT_MESSAGES)) {
          EntityTweetUser etuDMs =
              new EntityTweetUser(users.get(i).getId(), TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES);
          if (!PreferenceUtils.getStatusWorkApp(context)
              && type != OnAlarmReceiver.ALARM_ONLY_TIMELINE) {
            InfoSaveTweets info = etuDMs.saveTweets(context, twitter);
            if (info.getNewMessages() > 0 && dms) {
              userNotification.setIdsDMs(info.getIds());
            }
          }
          totalDMsAWD += etuDMs.getValueNewCount();
        }

        // DIRECTOS ENVIADOS

        if (!PreferenceUtils.getStatusWorkApp(context)
            && type != OnAlarmReceiver.ALARM_ONLY_TIMELINE) {
          EntityTweetUser etuSentDMs =
              new EntityTweetUser(
                  users.get(i).getId(), TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES);
          etuSentDMs.saveTweets(context, twitter);
        }

        mUserNotifications.add(userNotification);

      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }