version:3.1
fix: update:更改主页样式,完善闹钟
This commit is contained in:
@@ -33,6 +33,7 @@ import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
@@ -209,6 +210,19 @@ public class AlarmUtils {
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
public void deleteAllAlarmClock() {
|
||||
HashSet<PendingIntent> pendingIntents = getOldPendingIntents();
|
||||
Iterator<PendingIntent> pendingIntentIterator = pendingIntents.iterator();
|
||||
while (pendingIntentIterator.hasNext()) {
|
||||
PendingIntent pendingIntent = pendingIntentIterator.next();
|
||||
alarmManager.cancel(pendingIntent);
|
||||
pendingIntentIterator.remove();
|
||||
}
|
||||
List<AlarmClockData> alarmClockData = getAllAlarms();
|
||||
for (AlarmClockData data : alarmClockData) {
|
||||
deleteAlarmClock(data.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有Alarm
|
||||
@@ -258,9 +272,15 @@ public class AlarmUtils {
|
||||
if (pendingIntents == null) {
|
||||
pendingIntents = getOldPendingIntents();
|
||||
}
|
||||
for (PendingIntent pendingIntent : pendingIntents) {
|
||||
Iterator<PendingIntent> pendingIntentIterator = pendingIntents.iterator();
|
||||
while (pendingIntentIterator.hasNext()) {
|
||||
PendingIntent pendingIntent = pendingIntentIterator.next();
|
||||
alarmManager.cancel(pendingIntent);
|
||||
pendingIntentIterator.remove();
|
||||
}
|
||||
// for (PendingIntent pendingIntent : pendingIntents) {
|
||||
//
|
||||
// }
|
||||
List<AlarmClockData> newData = mergeData(data);
|
||||
for (AlarmClockData clockData : newData) {
|
||||
setAlarm(clockData);
|
||||
@@ -276,8 +296,10 @@ public class AlarmUtils {
|
||||
*/
|
||||
private List<AlarmClockData> mergeData(List<AlarmClockData> alarmClockDataList) {
|
||||
HashMap<Integer, AlarmClockData> alarmClockDataMap = new HashMap<>();
|
||||
for (AlarmClockData alarmClockData : alarmClockDataList) {
|
||||
alarmClockDataMap.put(alarmClockData.getId(), alarmClockData);
|
||||
if (alarmClockDataList != null) {
|
||||
for (AlarmClockData alarmClockData : alarmClockDataList) {
|
||||
alarmClockDataMap.put(alarmClockData.getId(), alarmClockData);
|
||||
}
|
||||
}
|
||||
HashMap<Integer, AlarmClockData> oldData = getOldData();
|
||||
List<AlarmClockData> deleteData = new ArrayList<>();
|
||||
@@ -291,6 +313,9 @@ public class AlarmUtils {
|
||||
}
|
||||
|
||||
List<AlarmClockData> newData = new ArrayList<>();
|
||||
if (alarmClockDataList == null) {
|
||||
return newData;
|
||||
}
|
||||
for (AlarmClockData alarm : alarmClockDataList) {
|
||||
AlarmClockData oldAlarm = oldData.get(alarm.getId());
|
||||
if (oldAlarm == null) {
|
||||
@@ -403,12 +428,14 @@ public class AlarmUtils {
|
||||
int hour = Integer.parseInt(timeSplit[0]);
|
||||
int minute = Integer.parseInt(timeSplit[1]);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH),
|
||||
c.get(Calendar.DAY_OF_MONTH), hour, minute, 0);
|
||||
int year = c.get(Calendar.YEAR);
|
||||
int month = c.get(Calendar.MONTH);
|
||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
c.set(year, month, day, hour, minute, 0);
|
||||
long mTimeInfo = c.getTimeInMillis();
|
||||
Log.e(TAG, "getTimestamp: " + mTimeInfo);
|
||||
long actualTime = mTimeInfo > System.currentTimeMillis() ? mTimeInfo : mTimeInfo + ONE_DAY_TIME;
|
||||
return actualTime;
|
||||
// long actualTime = mTimeInfo > System.currentTimeMillis() ? mTimeInfo : mTimeInfo + ONE_DAY_TIME;
|
||||
return mTimeInfo;
|
||||
} else {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
try {
|
||||
@@ -434,13 +461,13 @@ public class AlarmUtils {
|
||||
}
|
||||
|
||||
/*一次性*/
|
||||
private static final int ONCE = 1;
|
||||
public static final int ONCE = 1;
|
||||
/*每天*/
|
||||
private static final int LOOP = 2;
|
||||
public static final int LOOP = 2;
|
||||
/*周一到周五*/
|
||||
private static final int WORKING_DAY = 3;
|
||||
public static final int WORKING_DAY = 3;
|
||||
/*休息日*/
|
||||
private static final int OFF_DAY = 4;
|
||||
public static final int OFF_DAY = 4;
|
||||
|
||||
/**
|
||||
* 设置闹钟
|
||||
@@ -475,13 +502,13 @@ public class AlarmUtils {
|
||||
}
|
||||
break;
|
||||
case LOOP:
|
||||
setDayLoopAlarm(MainService.ALARMWAKEUP, title, id, timeStamp);
|
||||
setDayLoopAlarm(MainService.ALARMWAKEUP, title, id, timeString);
|
||||
break;
|
||||
case WORKING_DAY:
|
||||
|
||||
setWorkDayAlarm(MainService.ALARMWAKEUP, title, id, timeString);
|
||||
break;
|
||||
case OFF_DAY:
|
||||
|
||||
setOffDayAlarm(MainService.ALARMWAKEUP, title, id, timeString);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -498,17 +525,28 @@ public class AlarmUtils {
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setOnceAlarm: " + "id: " + requestCode + " title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param action
|
||||
* @param requestCode
|
||||
* @param timestamp 设置循环周期为一天的闹钟
|
||||
* @param timeString 设置循环周期为一天的闹钟
|
||||
*/
|
||||
public void setDayLoopAlarm(String action, String extra, int requestCode, long timestamp) {
|
||||
setLoopAlarm(action, extra, requestCode, AlarmManager.INTERVAL_DAY, timestamp);
|
||||
public void setDayLoopAlarm(String action, String extra, int requestCode, String timeString) {
|
||||
long timestamp = getTimestamp(timeString);
|
||||
if (System.currentTimeMillis() > timestamp) {
|
||||
timestamp += AlarmManager.INTERVAL_DAY;
|
||||
}
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setDayLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
// setLoopAlarm(action, extra, requestCode, AlarmManager.INTERVAL_DAY, timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -536,24 +574,49 @@ public class AlarmUtils {
|
||||
Log.e(TAG, "setLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
public void setWorkDayAlarm(String action, String extra, int requestCode, long intervalMillis, long timestamp) {
|
||||
public void setWorkDayAlarm(String action, String extra, int requestCode, String timeString) {
|
||||
long timestamp = getTimestamp(timeString);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int day_of_week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
switch (day_of_week) {
|
||||
case 6:
|
||||
case 7:
|
||||
timestamp += (8 - day_of_week) * AlarmManager.INTERVAL_DAY;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setWindow(AlarmManager.RTC_WAKEUP, timestamp, intervalMillis, startPendingIntent);
|
||||
Log.e(TAG, "setLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setWorkDayAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
public void setOffDayAlarm(String action, String extra, int requestCode, long intervalMillis, long timestamp) {
|
||||
public void setOffDayAlarm(String action, String extra, int requestCode, String timeString) {
|
||||
long timestamp = getTimestamp(timeString);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int day_of_week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
switch (day_of_week) {
|
||||
case 6:
|
||||
if (System.currentTimeMillis() > timestamp) {
|
||||
timestamp += AlarmManager.INTERVAL_DAY;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
default:
|
||||
timestamp += (6 - day_of_week) * AlarmManager.INTERVAL_DAY;
|
||||
break;
|
||||
}
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra("title", extra);
|
||||
intent.putExtra("id", requestCode);
|
||||
PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
pendingIntents.add(startPendingIntent);
|
||||
alarmManager.setWindow(AlarmManager.RTC_WAKEUP, timestamp, intervalMillis, startPendingIntent);
|
||||
Log.e(TAG, "setLoopAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timestamp, startPendingIntent);
|
||||
Log.e(TAG, "setOffDayAlarm: " + "title: " + extra + " timeString: " + timestamp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user