Android Open Source - adamsonelearn Schedule Helper






From Project

Back to project page adamsonelearn.

License

The source code is released under:

MIT License

If you think the Android project adamsonelearn 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.jaselogic.adamsonelearn;
//from ww w  .  ja va  2  s .  c o  m
import java.util.regex.Pattern;

import android.text.format.Time;
import android.util.Log;

public class ScheduleHelper {
  public static int convertTimeToIntSlot(Time t) {
    int slot = 0;
    
    slot = (t.hour - 7) * 2;
    if(t.minute >= 30)
      slot++;
    
    return slot;
  }
  
  public static int convertStringToIntSlot(String timeSlotString) {
    int hour = Integer.parseInt(timeSlotString.substring(0, 2));
    int slot = -1;
    
    slot = (hour - 7) * 2;
    if (Integer.parseInt(timeSlotString.substring(3, 5)) == 30)
      slot++;
    
    return slot;
  }
  
  public static String convertIntToStringSlot(int start, int end) {
    StringBuilder sb = new StringBuilder(
        String.format( "%02d",((start / 2) + 7) )
        );
    
    sb.append(":");
    sb.append( (start % 2) == 0 ? "00" : "30" );
    sb.append("-");
    sb.append(
        String.format( "%02d",((end / 2) + 7) )
        );
    sb.append(":");
    sb.append( (end % 2) == 0 ? "00" : "30" );
    
    return sb.toString();
  }
  
  public static int convertStringToIntDaySlot(String daySlotString) {
    int daySlot = 0;
    final String[] daySlotPatterns = new String[] {
        "M", "T[WTu]", "W", "Th", "F", "S"
      };
      
    for(int j = 0; j < 6; j++) {
      Pattern pattern = Pattern.compile(daySlotPatterns[j]);
      if(pattern.matcher(daySlotString).find()) {
        daySlot |= (1 << j);
      }
    }
    return daySlot;
  }
  
  public static String convertIntToStringDaySlot(int slot) {
    String res;
    final String[] daySlotFull = new String[] {
      "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
    };
    final String[] daySlotShort = new String[] {
      "M", "T", "W", "Th", "F", "S"
    };
    
    Log.d("FULL", String.valueOf( (slot & (slot - 1)) == 0 ));
    
    //determine if power of two to decide if full or short
    if( (slot & (slot - 1)) == 0 ) { // full
      int c = 0;
      while( (slot >>= 1) != 0) {
        c++;
      }
      res = daySlotFull[c];
    } else { //short
      StringBuilder sb = new StringBuilder();
      for(int c = 0; slot != 0; c++) {
        if ( (slot & 1) == 1 ) {
          sb.append(daySlotShort[c]);
        }
        slot >>= 1;
      }
      res = sb.toString();
    }

    return res;
  }
}




Java Source Code List

com.jaselogic.adamsonelearn.AlertDialogBuilder.java
com.jaselogic.adamsonelearn.CurrDisplayAdapter.java
com.jaselogic.adamsonelearn.CurriculumFragment.java
com.jaselogic.adamsonelearn.CurriculumIntentService.java
com.jaselogic.adamsonelearn.CurriculumPageFragment.java
com.jaselogic.adamsonelearn.Dashboard.java
com.jaselogic.adamsonelearn.DownloadDocumentIntentService.java
com.jaselogic.adamsonelearn.DrawerListAdapter.java
com.jaselogic.adamsonelearn.HomeFragment.java
com.jaselogic.adamsonelearn.HomePageFragment.java
com.jaselogic.adamsonelearn.LoginIntentService.java
com.jaselogic.adamsonelearn.Main.java
com.jaselogic.adamsonelearn.NonSwipeViewPager.java
com.jaselogic.adamsonelearn.ScheduleHelper.java
com.jaselogic.adamsonelearn.SubjectIntentService.java
com.jaselogic.adamsonelearn.SubjectListAdapter.java
com.jaselogic.adamsonelearn.TodayListAdapter.java
com.jaselogic.adamsonelearn.UpdateIntentService.java
com.jaselogic.adamsonelearn.UpdatesListAdapter.java
com.jaselogic.adamsonelearn.YearSelectAdapter.java
com.viewpagerindicator.CirclePageIndicator.java
com.viewpagerindicator.IconPageIndicator.java
com.viewpagerindicator.IconPagerAdapter.java
com.viewpagerindicator.IcsLinearLayout.java
com.viewpagerindicator.LinePageIndicator.java
com.viewpagerindicator.PageIndicator.java
com.viewpagerindicator.TabPageIndicator.java
com.viewpagerindicator.TitlePageIndicator.java
com.viewpagerindicator.UnderlinePageIndicator.java