Android Open Source - keepmoving Utils






From Project

Back to project page keepmoving.

License

The source code is released under:

GNU General Public License

If you think the Android project keepmoving 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 it.rainbowbreeze.keepmoving.common;
// www.j  av a 2s  .  c om
import java.util.Calendar;
import java.util.Locale;

import it.rainbowbreeze.keepmoving.domain.GeoPoint;
import it.rainbowbreeze.keepmoving.domain.Route;
import it.rainbowbreeze.keepmoving.domain.Weekdays;

/**
 * This file is part of KeepMoving. KeepMoving is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, version 2.
 * <p/>
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * <p/>
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * <p/>
 * Copyright Alfredo Morresi
 * <p/>
 * Created by Alfredo "Rainbowbreeze" Morresi on 16/06/14.
 */
public class Utils {
    /** Invalid timestamp */
    public static final int INVALID_TIMESTAMP = -1;

    public static final String MESSAGE_UPDATE_ALL_VIEWS = "it.rainbowbreeze.keepmoving.UPDATE_ALL_VIEWS";
    public static final String MESSAGE_REFRESH_TIME_VIEWS = "it.rainbowbreeze.keepmoving.REFRESH_TIME_VIEWS";

    public static final int NOTIFICATION_ID = 532;

    /**
     * Returns the numeric timestamp from a String representing the time
     * @param time
     * @return
     */
    public static int getTimestampFromTime(String time) {
        int index = time.indexOf(":");
        int hours = Integer.parseInt(time.substring(0, index));
        int minutes = Integer.parseInt(time.substring(index+1));
        return hours * 60 + minutes;
    }

    /**
     * Returns the string representation of the given timestamp
     * @param timestamp
     * @return
     */
    public static String getTimeFromTimestamp(int timestamp) {
        if (isTimestampInvalid(timestamp)) return null;

        int hour = timestamp / 60;
        int minutes = timestamp % 60;
        return String.format(Locale.ITALY, "%d:%02d", hour, minutes);
    }

    public static boolean isTimestampInvalid(int timestamp) {
        return INVALID_TIMESTAMP == timestamp;
    }

    public static int getCurrentTimestamp() {
        return getCurrentTimestamp(Calendar.getInstance());
    }

    public static int getCurrentTimestamp(Calendar calendar) {
        // Takes only the time part
        return calendar.get(Calendar.HOUR_OF_DAY) * 60 +
                calendar.get(Calendar.MINUTE);
    }

    /**
     * Returns the number of minutes before the first step of the route
     * @param route
     * @return
     */
    public static int getRemainingMinutesToRoute(Route route) {
        return route.getLeavingTimestamp() - getCurrentTimestamp();
    }

    public static Weekdays getCurrentDay() {
        return getCurrentDay(Calendar.getInstance());
    }

    public static Weekdays getCurrentDay(Calendar calendar) {
        //TODO implement this method
        return Weekdays.Mon;
    }
}




Java Source Code List

it.rainbowbreeze.keepmoving.ApplicationTest.java
it.rainbowbreeze.keepmoving.common.Config.java
it.rainbowbreeze.keepmoving.common.DaggerModule.java
it.rainbowbreeze.keepmoving.common.ILogManager.java
it.rainbowbreeze.keepmoving.common.LogManager.java
it.rainbowbreeze.keepmoving.common.MyApp.java
it.rainbowbreeze.keepmoving.common.Utils.java
it.rainbowbreeze.keepmoving.data.GeoPointDao.java
it.rainbowbreeze.keepmoving.data.GeoPointFixedRepository.java
it.rainbowbreeze.keepmoving.data.IGeoPointRepository.java
it.rainbowbreeze.keepmoving.domain.Coord.java
it.rainbowbreeze.keepmoving.domain.GeoPointTypes.java
it.rainbowbreeze.keepmoving.domain.GeoPoint.java
it.rainbowbreeze.keepmoving.domain.Route.java
it.rainbowbreeze.keepmoving.domain.Weekdays.java
it.rainbowbreeze.keepmoving.logic.PositionManager.java
it.rainbowbreeze.keepmoving.logic.RouteManager.java
it.rainbowbreeze.keepmoving.logic.TimetableController.java
it.rainbowbreeze.keepmoving.logic.TimetableModel.java
it.rainbowbreeze.keepmoving.ui.SpannableHelper.java
it.rainbowbreeze.keepmoving.ui.StepsArrayAdapter.java
it.rainbowbreeze.keepmoving.ui.TimetableActivity.java
it.rainbowbreeze.keepmoving.ui.TimetableActivity.java
it.rainbowbreeze.keepmoving.ui.TimetableFragment.java