Android Open Source - ho.la.urv Day






From Project

Back to project page ho.la.urv.

License

The source code is released under:

MIT License

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

Java Source Code

package eu.robertboloc.holaurv.models;
/*w  w w  .jav a 2s .  c o m*/
import java.util.ArrayList;
import java.util.List;

import org.joda.time.DateTime;
import org.joda.time.Period;

public class Day {

    public static final int MONDAY = 0;
    public static final int TUESDAY = 1;
    public static final int WEDNESDAY = 2;
    public static final int THURSDAY = 3;
    public static final int FRIDAY = 4;
    public static final int SATURDAY = 5;
    public static final int SUNDAY = 6;

    String shiftRaw;

    /**
     * List of entries.
     */
    final List<Entry> entries = new ArrayList<Entry>();

    /**
     * Returns the shift in display mode XX:XX
     * 
     * @return String
     */
    public String getShiftDisplay() {
        return shiftRaw.replaceAll("[^0-9:]", "");
    }

    /**
     * Updates the shiftRaw value.
     * 
     * @param shiftRaw
     *            String
     */
    public void setShiftRaw(String shiftRaw) {
        this.shiftRaw = shiftRaw;
    }

    /**
     * Adds an entry.
     * 
     * @param entry
     *            Entry
     */
    public void addEntry(Entry entry) {
        entries.add(entry);
    }

    /**
     * Obtains an entry if it exists.
     * 
     * @param entry
     *            Entry.FIRST_ENTRY | Entry.SECOND_ENTRY | Entry.FIRST_EXIT |
     *            Entry.SECOND_EXIT
     * @return Entry
     */
    public Entry getEntry(int entry) {
        if (!entries.isEmpty() && entry < entries.size()) {
            return entries.get(entry);
        }
        return null;
    }

    /**
     * Calculates the accumulated time between an entry and an exit.
     * 
     * @param entry
     *            Entry.FIRST_ENTRY | Entry.SECOND_ENTRY
     * @param exit
     *            Entry.SECOND_EXIT | Entry.SECOND_EXIT
     * @return Period
     */
    public Period getAccumulate(int entry, int exit) {
        if (getEntry(entry) != null && getEntry(exit) != null) {

            DateTime entryDateTime = new DateTime(2000, 1, 1, getEntry(entry)
                    .getHour(), getEntry(entry).getMinute());
            DateTime exitDateTime = new DateTime(2000, 1, 1, getEntry(exit)
                    .getHour(), getEntry(exit).getMinute());

            return new Period(entryDateTime, exitDateTime).normalizedStandard();
        }

        return null;
    }

    /**
     * With no arguments returns the daily accumulate.
     * 
     * @return Period
     */
    public Period getAccumulate() {

        Period firstAccumulate = getAccumulate(Entry.FIRST_ENTRY,
                Entry.FIRST_EXIT);

        if (firstAccumulate != null) {
            Period secondAccumulate = getAccumulate(Entry.SECOND_ENTRY,
                    Entry.SECOND_EXIT);

            if (secondAccumulate != null) {
                firstAccumulate = firstAccumulate.plusHours(
                        secondAccumulate.getHours()).plusMinutes(
                        secondAccumulate.getMinutes());
            }

            // Always normalize
            return firstAccumulate.normalizedStandard();
        }

        return null;
    }

    /**
     * Returns the current day of the week in an integer format, shifted by one
     * so that MONDAY is 0.
     * 
     * @return int
     */
    public static int today() {
        DateTime date = DateTime.now();
        return date.getDayOfWeek() - 1;
    }
}




Java Source Code List

eu.robertboloc.holaurv.HoLaURV.java
eu.robertboloc.holaurv.activities.AboutActivity.java
eu.robertboloc.holaurv.activities.DisplayActivity.java
eu.robertboloc.holaurv.activities.LoginActivity.java
eu.robertboloc.holaurv.activities.ReportActivity.java
eu.robertboloc.holaurv.adapters.DayCollectionPagerAdapter.java
eu.robertboloc.holaurv.fragments.DayObjectFragment.java
eu.robertboloc.holaurv.helpers.Evalos.java
eu.robertboloc.holaurv.helpers.TypefaceSpan.java
eu.robertboloc.holaurv.models.Day.java
eu.robertboloc.holaurv.models.Entry.java
eu.robertboloc.holaurv.models.Week.java