/*
* Copyright (C) 2007 The Android Open Source 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.
*/
package com.android.deskclock;
import android.app.AlarmManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Parcel;
import android.provider.Settings;
import android.text.format.DateFormat;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
/**
* The Alarms provider supplies info about Alarm Clock settings
*/
public class Alarms {
// This action triggers the AlarmReceiver as well as the AlarmKlaxon. It
// is a public action used in the manifest for receiving Alarm broadcasts
// from the alarm manager.
public static final String ALARM_ALERT_ACTION = "com.android.deskclock.ALARM_ALERT";
// A public action sent by AlarmKlaxon when the alarm has stopped sounding
// for any reason (e.g. because it has been dismissed from AlarmAlertFullScreen,
// or killed due to an incoming phone call, etc).
public static final String ALARM_DONE_ACTION = "com.android.deskclock.ALARM_DONE";
// AlarmAlertFullScreen listens for this broadcast intent, so that other applications
// can snooze the alarm (after ALARM_ALERT_ACTION and before ALARM_DONE_ACTION).
public static final String ALARM_SNOOZE_ACTION = "com.android.deskclock.ALARM_SNOOZE";
// AlarmAlertFullScreen listens for this broadcast intent, so that other applications
// can dismiss the alarm (after ALARM_ALERT_ACTION and before ALARM_DONE_ACTION).
public static final String ALARM_DISMISS_ACTION = "com.android.deskclock.ALARM_DISMISS";
// This is a private action used by the AlarmKlaxon to update the UI to
// show the alarm has been killed.
public static final String ALARM_KILLED = "alarm_killed";
// Extra in the ALARM_KILLED intent to indicate to the user how long the
// alarm played before being killed.
public static final String ALARM_KILLED_TIMEOUT = "alarm_killed_timeout";
// This string is used to indicate a silent alarm in the db.
public static final String ALARM_ALERT_SILENT = "silent";
// This intent is sent from the notification when the user cancels the
// snooze alert.
public static final String CANCEL_SNOOZE = "cancel_snooze";
// This string is used when passing an Alarm object through an intent.
public static final String ALARM_INTENT_EXTRA = "intent.extra.alarm";
// This extra is the raw Alarm object data. It is used in the
// AlarmManagerService to avoid a ClassNotFoundException when filling in
// the Intent extras.
public static final String ALARM_RAW_DATA = "intent.extra.alarm_raw";
private static final String PREF_SNOOZE_IDS = "snooze_ids";
private static final String PREF_SNOOZE_TIME = "snooze_time";
private final static String DM12 = "E h:mm aa";
private final static String DM24 = "E kk:mm";
private final static String M12 = "h:mm aa";
// Shared with DigitalClock
final static String M24 = "kk:mm";
final static int INVALID_ALARM_ID = -1;
/**
* Creates a new Alarm and fills in the given alarm's id.
*/
public static long addAlarm(Context context, Alarm alarm) {
ContentValues values = createContentValues(alarm);
Uri uri = context.getContentResolver().insert(
Alarm.Columns.CONTENT_URI, values);
alarm.id = (int) ContentUris.parseId(uri);
long timeInMillis = calculateAlarm(alarm);
if (alarm.enabled) {
clearSnoozeIfNeeded(context, timeInMillis);
}
setNextAlert(context);
return timeInMillis;
}
/**
* Removes an existing Alarm. If this alarm is snoozing, disables
* snooze. Sets next alert.
*/
public static void deleteAlarm(Context context, int alarmId) {
if (alarmId == INVALID_ALARM_ID) return;
ContentResolver contentResolver = context.getContentResolver();
/* If alarm is snoozing, lose it */
disableSnoozeAlert(context, alarmId);
Uri uri = ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId);
contentResolver.delete(uri, "", null);
setNextAlert(context);
}
/**
* Queries all alarms
* @return cursor over all alarms
*/
public static Cursor getAlarmsCursor(ContentResolver contentResolver) {
return contentResolver.query(
Alarm.Columns.CONTENT_URI, Alarm.Columns.ALARM_QUERY_COLUMNS,
null, null, Alarm.Columns.DEFAULT_SORT_ORDER);
}
// Private method to get a more limited set of alarms from the database.
private static Cursor getFilteredAlarmsCursor(
ContentResolver contentResolver) {
return contentResolver.query(Alarm.Columns.CONTENT_URI,
Alarm.Columns.ALARM_QUERY_COLUMNS, Alarm.Columns.WHERE_ENABLED,
null, null);
}
private static ContentValues createContentValues(Alarm alarm) {
ContentValues values = new ContentValues(8);
// Set the alarm_time value if this alarm does not repeat. This will be
// used later to disable expire alarms.
long time = 0;
if (!alarm.daysOfWeek.isRepeatSet()) {
time = calculateAlarm(alarm);
}
values.put(Alarm.Columns.ENABLED, alarm.enabled ? 1 : 0);
values.put(Alarm.Columns.HOUR, alarm.hour);
values.put(Alarm.Columns.MINUTES, alarm.minutes);
values.put(Alarm.Columns.ALARM_TIME, time);
values.put(Alarm.Columns.DAYS_OF_WEEK, alarm.daysOfWeek.getCoded());
values.put(Alarm.Columns.VIBRATE, alarm.vibrate);
values.put(Alarm.Columns.MESSAGE, alarm.label);
// A null alert Uri indicates a silent alarm.
values.put(Alarm.Columns.ALERT, alarm.alert == null ? ALARM_ALERT_SILENT
: alarm.alert.toString());
return values;
}
private static void clearSnoozeIfNeeded(Context context, long alarmTime) {
// If this alarm fires before the next snooze, clear the snooze to
// enable this alarm.
SharedPreferences prefs = context.getSharedPreferences(AlarmClock.PREFERENCES, 0);
// Get the list of snoozed alarms
final Set<String> snoozedIds = prefs.getStringSet(PREF_SNOOZE_IDS, new HashSet<String>());
for (String snoozedAlarm : snoozedIds) {
final long snoozeTime = prefs.getLong(getAlarmPrefSnoozeTimeKey(snoozedAlarm), 0);
if (alarmTime < snoozeTime) {
final int alarmId = Integer.parseInt(snoozedAlarm);
clearSnoozePreference(context, prefs, alarmId);
}
}
}
/**
* Return an Alarm object representing the alarm id in the database.
* Returns null if no alarm exists.
*/
public static Alarm getAlarm(ContentResolver contentResolver, int alarmId) {
Cursor cursor = contentResolver.query(
ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId),
Alarm.Columns.ALARM_QUERY_COLUMNS,
null, null, null);
Alarm alarm = null;
if (cursor != null) {
if (cursor.moveToFir
没有合适的资源?快使用搜索试试~ 我知道了~
Android应用源码之DeskClock.zip项目安卓应用源码下载
共305个文件
png:151个
xml:116个
java:27个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 114 浏览量
2022-03-08
00:27:24
上传
评论
收藏 800KB ZIP 举报
温馨提示
Android应用源码之DeskClock.zip项目安卓应用源码下载Android应用源码之DeskClock.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码之DeskClock.zip项目安卓应用源码下载 (305个子文件)
HEAD 41B
undim.html 248B
index 31KB
Alarms.java 23KB
DeskClock.java 21KB
SetAlarm.java 13KB
AlarmClock.java 11KB
Alarm.java 11KB
AlarmKlaxon.java 11KB
AlarmAlertFullScreen.java 10KB
AlarmReceiver.java 9KB
Screensaver.java 7KB
DigitalClock.java 5KB
AlarmProvider.java 5KB
SettingsActivity.java 5KB
HandleSetAlarm.java 4KB
AlarmAlert.java 3KB
AlarmPreference.java 3KB
RepeatPreference.java 3KB
AlarmDatabaseHelper.java 3KB
AndroidClockTextView.java 2KB
AnalogAppWidgetProvider.java 2KB
AlarmInitReceiver.java 2KB
TestAddAlarm.java 2KB
AlarmAlertWakeLock.java 2KB
Log.java 1KB
DontPressWithParentLayout.java 1KB
DeskClockLaunchPerformance.java 1KB
AsyncHandler.java 1KB
ToastMaster.java 1KB
CleanSpec.mk 2KB
Android.mk 417B
Android.mk 353B
MODULE_LICENSE_APACHE2 0B
NOTICE 10KB
in_call_alarm.ogg 21KB
fallbackring.ogg 21KB
ic_launcher_alarmclock.png 16KB
list_selector_background_pressed.9.png 11KB
ic_launcher_alarmclock.png 11KB
ic_setalarm_holo_dark.png 11KB
dialog.9.png 9KB
ic_widget_analog_clock.png 9KB
btn_in_call_round_selected.png 8KB
ic_widget_analog_clock.png 8KB
btn_in_call_round_pressed.png 8KB
btn_in_call_round_disable_focused.png 8KB
ic_setalarm_holo_dark.png 7KB
appwidget_clock_dial.png 6KB
preview.png 6KB
ic_launcher_alarmclock.png 6KB
ic_menu_clock_face.png 6KB
btn_in_call_round_normal.png 5KB
ic_clock_strip_alarm.png 5KB
ic_widget_analog_clock.png 5KB
dialog.9.png 5KB
ic_clock_strip_desk_clock.png 5KB
ic_clock_strip_gallery.png 5KB
ic_menu_alarms.png 5KB
ic_menu_clock_face.png 5KB
btn_in_call_round_selected.png 5KB
dialog.9.png 4KB
btn_in_call_round_pressed.png 4KB
ic_menu_desk_clock.png 4KB
btn_in_call_round_normal.png 4KB
ic_clock_strip_alarm.png 4KB
list_selector_background_pressed.9.png 4KB
appwidget_clock_dial.png 4KB
ic_setalarm_holo_dark.png 4KB
ic_round_brightness.png 4KB
ic_clock_strip_gallery.png 4KB
ic_clock_strip_home.png 3KB
ic_clock_strip_desk_clock.png 3KB
ic_dialog_time.png 3KB
ic_round_brightness.png 3KB
btn_in_call_round_disable_focused.png 3KB
ic_menu_alarms.png 3KB
ic_lock_idle_alarm_saver_dim.png 3KB
btn_in_call_round_disable.png 3KB
ic_clock_strip_music.png 3KB
ic_menu_clock_face.png 3KB
dialog_divider_horizontal_light.9.png 3KB
ic_clock_alarm_off.png 3KB
ic_clock_alarm_on.png 3KB
btn_in_call_round_selected.png 3KB
divider_vertical_dark.9.png 3KB
divider_vertical_dark.9.png 3KB
ic_menu_desk_clock.png 3KB
btn_in_call_round_pressed.png 3KB
list_selector_background_pressed.9.png 3KB
ic_clock_strip_home.png 3KB
btn_in_call_round_normal.png 3KB
appwidget_clock_dial.png 2KB
ic_clock_strip_alarm.png 2KB
ic_clock_brightness.png 2KB
dialog.9.png 2KB
ic_clock_strip_music.png 2KB
ic_lock_idle_alarm_saver.png 2KB
ic_clock_strip_gallery.png 2KB
ic_lock_idle_alarm.png 2KB
共 305 条
- 1
- 2
- 3
- 4
资源评论
yxkfw
- 粉丝: 76
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功