Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import java.util.Calendar; public class Main { public static boolean isCheckChangePermitted(Context context, Calendar date) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); String limitActivePref = sharedPrefs.getString("active-date-key", "ALLOW_ALL"); Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); Calendar yesterday; switch (limitActivePref) { case "ALLOW_CURRENT": return (date.compareTo(today) == 0); case "ALLOW_CURRENT_AND_NEXT_DAY": yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DATE, -1); return (date.compareTo(yesterday) >= 0); case "ALLOW_CURRENT_AND_NEXT_DAY_AND_WEEKEND": yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DATE, today.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY ? -2 : -1); return (date.compareTo(yesterday) >= 0); case "ALLOW_ALL": default: return true; } } }