/* * Copyright (C) 2014 AChep@xda <artemchep@gmail.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ package com.achep.acdisplay.services; import android.accessibilityservice.AccessibilityServiceInfo; import android.app.Notification; import android.os.Parcelable; import android.view.accessibility.AccessibilityEvent; import com.achep.acdisplay.notifications.NotificationPresenter; import com.achep.acdisplay.notifications.OpenNotification; import com.achep.base.Device; /** * Created by Artem Chepurnoy on 06.09.2014. */ public class AccessibilityService extends android.accessibilityservice.AccessibilityService { private static final String TAG = "AccessibilityService"; @Override public void onServiceConnected() { AccessibilityServiceInfo info = new AccessibilityServiceInfo(); info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC; info.notificationTimeout = 100; setServiceInfo(info); } @Override public void onAccessibilityEvent(AccessibilityEvent event) { switch (event.getEventType()) { case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: Parcelable parcelable = event.getParcelableData(); if (parcelable instanceof Notification) { if (Device.hasJellyBeanMR2Api()) { // No need to use the accessibility service // instead of NotificationListener. return; } Notification notification = (Notification) parcelable; OpenNotification openNotification = OpenNotification.newInstance(notification); NotificationPresenter.getInstance().postNotificationFromMain(this, openNotification, 0); } break; } } /** * {@inheritDoc} */ @Override public void onInterrupt() { /* unused */ } }