Android Open Source - android-002 Alarm Time Interval






From Project

Back to project page android-002.

License

The source code is released under:

Apache License

If you think the Android project android-002 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 com.michaelfitzmaurice.dailyselfie;
/*from w  w  w.  jav  a  2s .c o  m*/

public class AlarmTimeInterval {
  
  private static final long ONE_MINUTE_IN_MS = 1000 * 60;
  private static final long ONE_HOUR_IN_MS = ONE_MINUTE_IN_MS * 60;
  private static final long ONE_DAY_IN_MS = ONE_HOUR_IN_MS * 24;
  
  private static final String FIELD_SEPARATOR = ",";
  
  private int days;
  private int hours;
  private int minutes;
  
  public AlarmTimeInterval() {
      super();
    }
  
  public AlarmTimeInterval(String interval) {
    
    String[] fields = interval.split(FIELD_SEPARATOR);
    if (fields == null || fields.length != 3) {
      throw new IllegalArgumentException(
        "'" + interval + 
        "' is not a valid AlarmTimeInterval representation");
    }
    
    this.days = Integer.parseInt(fields[0]);
    this.hours = Integer.parseInt(fields[1]);
    this.minutes = Integer.parseInt(fields[2]);
  }

  public AlarmTimeInterval(int days, int hours, int minutes) {
      super();
      this.days = days;
      this.hours = hours;
      this.minutes = minutes;
    }

  public int getDays() {
    return days;
  }

  public int getHours() {
    return hours;
  }

  public int getMinutes() {
    return minutes;
  }
  
  public void setDays(int days) {
    this.days = days;
  }

  public void setHours(int hours) {
    this.hours = hours;
  }

  public void setMinutes(int minutes) {
    this.minutes = minutes;
  }
  
  public boolean isZero() {
    return (toMilliseconds() == 0);
  }
  
  public long toMilliseconds() {
    
    return ( getDays() * ONE_DAY_IN_MS ) 
        + ( getHours() * ONE_HOUR_IN_MS ) 
        + ( getMinutes() * ONE_MINUTE_IN_MS );
  }

  @Override
    public String toString() {
      return "AlarmTimeInterval [days=" + days + ", hours=" + hours
              + ", minutes=" + minutes + "]";
    }
  
  public String serialiseToString() {
    
    StringBuilder sb = new StringBuilder();
    sb.append(days);
    sb.append(FIELD_SEPARATOR);
    sb.append(hours);
    sb.append(FIELD_SEPARATOR);
    sb.append(minutes);
    
    return sb.toString();
  }
  
}




Java Source Code List

com.michaelfitzmaurice.android.modernart.MainActivity.java
com.michaelfitzmaurice.dailyselfie.AlarmReceiver.java
com.michaelfitzmaurice.dailyselfie.AlarmTimeInterval.java
com.michaelfitzmaurice.dailyselfie.Alarms.java
com.michaelfitzmaurice.dailyselfie.SelfieDetailActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListViewAdapter.java
com.michaelfitzmaurice.dailyselfie.SelfieRecord.java
com.michaelfitzmaurice.dailyselfie.settings.ReminderIntervalDialogPreference.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsActivity.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsFragment.java
course.labs.contentproviderlab.MockLocationProvider.java
course.labs.contentproviderlab.PlaceDownloaderTask.java
course.labs.contentproviderlab.PlaceRecord.java
course.labs.contentproviderlab.PlaceViewActivity.java
course.labs.contentproviderlab.PlaceViewAdapter.java
course.labs.contentproviderlab.provider.PlaceBadgeContentProvider.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.graphicslab.BubbleActivity.java
course.labs.locationlab.MockLocationProvider.java
course.labs.locationlab.PlaceDownloaderTask.java
course.labs.locationlab.PlaceRecord.java
course.labs.locationlab.PlaceViewActivity.java
course.labs.locationlab.PlaceViewAdapter.java
course.labs.notificationslab.DownloaderTask.java
course.labs.notificationslab.FeedFragment.java
course.labs.notificationslab.FriendsFragment.java
course.labs.notificationslab.MainActivity.java
course.labs.notificationslab.SelectionListener.java
course.labs.notificationslab.TestFrontEndActivity.java