呼吸灯仅提示15分钟
来源:互联网 发布:redhat怎么安装mysql 编辑:程序博客网 时间:2024/04/28 13:05
呼吸灯仅提示15分钟
这里只是大致记录一下framework 层的大致修改方法.
每次NotificationManagerService 在处理通知的时候会判断该通知是否需要开启led灯,如果需要开启的话,首先判断设置里面关于这个功能的开关是否开启,如果是开启的话,如果这个通知和同一个通知不是同一个id,就设置一个15分钟的闹钟来在关闭这个led灯.
其中关闭是在闹钟时间到了之后,发出指定广播来处理的,所以我们在创建NotificationManagerService的时候需要注册一个广播监听器.
NotificationManagerService.java
@Override
public void onStart() {
...
//zhangle add for notification light start 20150513
/* Uri uri = android.provider.Settings.System.getUriFor(DISPLAY_LIGHT_TURN_QUARTER);
getContext().getContentResolver().registerContentObserver(uri, false, myNotificationLightContentObserver);*/
IntentFilter myFilter = new IntentFilter();
myFilter.addAction(DOOV_LED_TURN_OFF_ACTION);
getContext().registerReceiverAsUser(new MyBroadCastReceiver(),UserHandle.ALL, myFilter,null,
null);
Log.d(TAG,"register DOOV_LED_TURN_OFF_ACTION");
//zhangle add for notification light end 20150513
}
// lock on mNotificationList
void updateLightsLocked()
{
Log.d(TAG,"updateLightsLocked mLights size=" + mLights.size());
// handle notification lights
NotificationRecord ledNotification = null;
while (ledNotification == null && !mLights.isEmpty()) {
final String owner = mLights.get(mLights.size() - 1);
Log.d(TAG,"updateLightsLocked owner=" + owner);
ledNotification = mNotificationsByKey.get(owner);
if (ledNotification == null) {
Slog.wtfStack(TAG, "LED Notification does not exist: " + owner);
mLights.remove(owner);
}
}
//zhangle add for notification light start 20150513
int value = Settings.System.getInt(getContext().getContentResolver(), DISPLAY_LIGHT_TURN_QUARTER, 0);
Log.d(TAG,"updateLightsLocked value=" +value + " ledNotification=" + ledNotification+ " mNotificationPulseEnabled=" + mNotificationPulseEnabled);
//zhangle add for notification light end 20150513
// handle notification lights
// Don't flash while we are in a call or screen is on
//if (mLedNotification == null || mInCall || mScreenOn) {
/// M: [ALPS01244800] Flash Notification LED regardless of screen state
if (ledNotification == null || mInCall /*|| mScreenOn*/ || mDmLock || mPplLock) {
mNotificationLight.turnOff();
mStatusBar.notificationLightOff();
} else {
final Notification ledno = ledNotification.sbn.getNotification();
int ledARGB = ledno.ledARGB;
int ledOnMS = ledno.ledOnMS;
int ledOffMS = ledno.ledOffMS;
if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
ledARGB = mDefaultNotificationColor;
ledOnMS = mDefaultNotificationLedOn;
ledOffMS = mDefaultNotificationLedOff;
}
if (mNotificationPulseEnabled) {
// pulse repeatedly
/// M: add log for lights debug @{
if (DBG) {
Log.d(TAG, "notification setFlashing ledOnMS = " + ledOnMS + " ledOffMS = " + ledOffMS);
}
/// M: add log for lights debug @{
mNotificationLight.setFlashing(ledARGB, Light.LIGHT_FLASH_TIMED,
ledOnMS, ledOffMS);
//zhangle add for notification light start 20150513
StatusBarNotification sbn = ledNotification.getSbn();
int notification_id = -1;
if(null != sbn){
notification_id = sbn.getId();
Log.d(TAG, "notification notification_id =" + notification_id + " mNotification_id=" + mNotification_id);
}
if(value >0 && null != sbn && mNotification_id != sbn.getId() ){//测试时发现qq 会重复发同一个通知.
turnOffLightLater();
mNotification_id = notification_id;
}
//zhangle add for notification light end 20150513
}
// let SystemUI make an independent decision
mStatusBar.notificationLightPulse(ledARGB, ledOnMS, ledOffMS);
}
}
//zhangle add for notification light start 20150513
private final int delaySeconds = 15*60;
private final int delaySeconds_test = 20;
private int mNotification_id = -1;
private AlarmManager am = null;
private final static String DOOV_LED_TURN_OFF_ACTION = "android.alarm.doov.led.action";
public void turnOffLightLater(){
Log.d(TAG,"turnOffLightLater " );
setAlarm();
}
class MyBroadCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int value = getValue();
Log.d(TAG, "intent.action=" + intent.getAction() + " value=" + value);
if(value >0){
mNotificationLight.turnOff();
mStatusBar.notificationLightOff();
if(null != mLights){
Log.d(TAG, "onReceive mLights=" + mLights.size());
mLights.clear();
}
}
}
}
public Calendar getTimeInSeconds(int amount){
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, amount);
Log.d(TAG,"getTimeInSeconds" +calendar.getTime());
return calendar;
}
public void setAlarm() {
if(am == null){
am = (AlarmManager) this.getContext().getSystemService(Context.ALARM_SERVICE);
}
Intent i = new Intent(DOOV_LED_TURN_OFF_ACTION);
PendingIntent sender = PendingIntent.getBroadcast(this.getContext(), 0, i,PendingIntent.FLAG_CANCEL_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, getTimeInSeconds(delaySeconds).getTimeInMillis(), sender);
Log.d(TAG,"setAlarm");
}
public int getValue() {
return android.provider.Settings.System.getInt(getContext().getContentResolver(), DISPLAY_LIGHT_TURN_QUARTER, 0);
}
//zhangle add for notification light end 20150513
0 0
- 呼吸灯仅提示15分钟
- 呼吸灯
- 呼吸灯
- 呼吸灯
- 呼吸灯
- Qt实用技巧:会呼吸的痛(呼吸点/呼吸灯)
- Qt实用技巧:会呼吸的痛(呼吸点/呼吸灯)
- BreatheLight 呼吸灯
- 呼吸灯程序
- STC15F104E 呼吸灯
- arduino呼吸灯
- 呼吸灯-html&canvas
- arduino 呼吸灯
- WPF 呼吸灯特效
- 呼吸灯的实现
- STM32呼吸灯
- vhdl呼吸灯源码
- 呼吸灯 效果
- 238. Product of Array Except Self
- ubuntu opencv 2.7.9安装
- 错误解决办法 error MSB8031:Building an MFC a non-Unicode charater set is deprecated .
- 实际开发中(维护)中常用的mysql相关命令精华总结
- jquery监听回车
- 呼吸灯仅提示15分钟
- 验证框架的配置及validation.xml常用的验证规则(Struts2的输入验证详解)
- $CI =& get_instance();
- 在android中关于onSaveInstanceState(),调用时机
- react native封装UI
- linux下cp目录时排除一个或者多个目录的实现方法
- Android之根据Uri获得图片或视频文件路径(解决4.4以上版本得不到路径的情况)
- 【LeetCode题解】链表Linked Lis
- Devexpress 11.1.8 .net 2.0时代最后一个版本