Android examples for java.util:Time
return Time Constraint Met
/*//w w w . jav a 2 s. c o m * Copyright (C) 2013 Android Open Kang Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.app.AlarmManager; import android.app.PendingIntent; import android.provider.ContactsContract.PhoneLookup; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; import android.media.RingtoneManager; import android.net.Uri; import android.preference.PreferenceManager; import android.provider.Settings; import android.telephony.SmsManager; import java.util.Calendar; public class Main{ private static final int FULL_DAY = 1440; private static final int TIME_LIMIT = 30; public static boolean returnTimeConstraintMet(Context context, int firstCallTime, int dayOfFirstCall) { int currentMinutes = returnTimeInMinutes(); int dayOfMonth = returnDayOfMonth(); // New Day, start at zero if (dayOfMonth != dayOfFirstCall) { // Less or Equal to 30 minutes until midnight if (firstCallTime >= (FULL_DAY - TIME_LIMIT)) { if ((currentMinutes >= 0) && (currentMinutes <= TIME_LIMIT)) { int remainderDayOne = FULL_DAY - firstCallTime; if ((remainderDayOne + currentMinutes) <= TIME_LIMIT) { return true; } else { return false; } } else { return false; } } else { // new day and prior call happened with more than // 30 minutes remaining in day return false; } } else { // Same day - simple subtraction: or you need to get out more // and it's been a month since your last call, reboot, or reschedule if ((currentMinutes - firstCallTime) <= TIME_LIMIT) { return true; } else { return false; } } } public static int returnTimeInMinutes() { Calendar calendar = Calendar.getInstance(); int currentMinutes = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); return currentMinutes; } public static int returnDayOfMonth() { Calendar calendar = Calendar.getInstance(); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); return dayOfMonth; } }