package com.cn.daming.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 android.util.Log;
import java.util.Calendar;
import java.text.DateFormatSymbols;
/**
* The Alarms provider supplies info about Alarm Clock settings
* 核心类,对Clock设置提供支持信息
*/
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.cn.daming.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.cn.daming.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.cn.daming.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.cn.daming.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";
// This string is used to identify the alarm id passed to SetAlarm from the
// list of alarms.
public static final String ALARM_ID = "alarm_id";
final static String PREF_SNOOZE_ID = "snooze_id";
final static String PREF_SNOOZE_TIME = "snooze_time";
private final static String DM12 = "E h:mm aa";
private final static String DM24 = "E k:mm";
private final static String M12 = "h:mm aa";
// Shared with DigitalClock
final static String M24 = "kk:mm";
/**
* 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 == -1) 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, alarm.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(DeskClockMainActivity.PREFERENCES, 0);
long snoozeTime = prefs.getLong(PREF_SNOOZE_TIME, 0);
if (alarmTime < snoozeTime) {
clearSnoozePreference(context, prefs);
}
}
/**
* 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.moveToFirst()) {
alarm = new Alarm(cursor);
}
cursor.close();
}
return alarm;
}
/**
* A convenience method to set an alarm in the Alarms
* content provider.
* @return Time when the alarm will fire.
*/
public static long setAlarm(Context context, Alarm alarm) {
ContentValues values = createContentValues(alarm);
ContentResolver resolver = context.getContentResolver();
resolver.update(
ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, a
没有合适的资源?快使用搜索试试~ 我知道了~
Android玲闹钟
共184个文件
png:74个
class:60个
xml:22个
5星 · 超过95%的资源 需积分: 43 6.8k 下载量 78 浏览量
2012-04-14
18:22:50
上传
评论 116
收藏 621KB RAR 举报
温馨提示
该闹钟是根据源码简化后的,我的csdn博客有截图,大家可以参考后下载, 链接地址:http://blog.csdn.net/wdaming1986/article/details/7461043
资源推荐
资源详情
资源评论
收起资源包目录
Android玲闹钟 (184个子文件)
resources.ap_ 145KB
DeskClockApp-4-10.apk 183KB
proguard.cfg 1KB
Alarms.class 13KB
SetAlarm.class 11KB
DeskClockMainActivity.class 9KB
AlarmKlaxon.class 9KB
AlarmAlertFullScreen.class 8KB
AlarmProvider.class 6KB
AlarmReceiver.class 6KB
DigitalClock.class 5KB
HandleSetAlarm.class 4KB
DeskClockMainActivity$AlarmTimeAdapter.class 4KB
Alarm.class 4KB
SettingsActivity.class 3KB
RepeatPreference.class 3KB
AlarmAlert.class 3KB
Alarm$DaysOfWeek.class 3KB
AlarmProvider$DatabaseHelper.class 2KB
R$drawable.class 2KB
R$string.class 2KB
AlarmKlaxon$1.class 2KB
DeskClockMainActivity$AlarmTimeAdapter$1.class 2KB
Alarm$Columns.class 2KB
SetAlarm$2.class 2KB
DigitalClock$1.class 2KB
AlarmPreference.class 2KB
AlarmAlertFullScreen$1.class 1KB
SetAlarm$4.class 1KB
SetAlarm$1.class 1KB
R$id.class 1KB
AlarmInitReceiver.class 1KB
RepeatPreference$1.class 1KB
DigitalClock$AmPm.class 1KB
AlarmKlaxon$4.class 1KB
AlarmAlertWakeLock.class 1KB
Alarm$1.class 1KB
AlarmAlert$2.class 1KB
DeskClockMainActivity$4.class 1KB
SetAlarm$6.class 1KB
AlarmKlaxon$2.class 1KB
SetAlarm$7.class 1010B
AlarmKlaxon$3.class 1002B
DigitalClock$1$1.class 939B
DeskClockMainActivity$2.class 911B
AlarmAlertFullScreen$3.class 907B
SetAlarm$3.class 873B
AlarmAlert$1.class 867B
DeskClockMainActivity$1.class 859B
AlarmAlertFullScreen$2.class 853B
DeskClockMainActivity$3.class 827B
R.class 821B
DigitalClock$FormatChangeObserver.class 817B
SetAlarm$5.class 802B
DontPressWithParentLayout.class 762B
ToastMaster.class 694B
R$style.class 648B
R$layout.class 589B
R$array.class 504B
R$menu.class 489B
R$raw.class 445B
R$xml.class 439B
R$attr.class 355B
.classpath 364B
classes.dex 68KB
Alarms.java 21KB
SetAlarm.java 13KB
DeskClockMainActivity.java 12KB
AlarmKlaxon.java 12KB
Alarm.java 11KB
AlarmAlertFullScreen.java 10KB
R.java 9KB
AlarmReceiver.java 8KB
AlarmProvider.java 7KB
DigitalClock.java 6KB
HandleSetAlarm.java 4KB
SettingsActivity.java 4KB
AlarmAlert.java 3KB
RepeatPreference.java 3KB
AlarmPreference.java 2KB
AlarmAlertWakeLock.java 2KB
AlarmInitReceiver.java 1KB
DontPressWithParentLayout.java 1KB
ToastMaster.java 1KB
in_call_alarm.ogg 21KB
fallbackring.ogg 21KB
ic_clock_strip_desk_clock.png 14KB
clock_launcher.png 13KB
ic_clock_strip_desk_clock.png 11KB
clock_launcher.png 11KB
list_selector_background_pressed.9.png 11KB
clock_launcher.png 8KB
ic_clock_strip_desk_clock.png 8KB
clock_launcher.png 6KB
ic_clock_strip_desk_clock.png 6KB
ic_clock_alarm_on.png 6KB
ic_clock_alarm_selected.png 6KB
ic_clock_alarm_off.png 6KB
ic_background.png 4KB
ic_clock_alarm_off.png 3KB
共 184 条
- 1
- 2
王宪明_ZeroSon
- 粉丝: 1905
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页