michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko; michael@0: michael@0: import android.app.Notification; michael@0: import android.app.Service; michael@0: import android.content.Intent; michael@0: import android.os.Binder; michael@0: import android.os.IBinder; michael@0: michael@0: public class NotificationService extends Service { michael@0: private final IBinder mBinder = new NotificationBinder(); michael@0: private NotificationHandler mHandler; michael@0: michael@0: @Override michael@0: public void onCreate() { michael@0: // This has to be initialized in onCreate in order to ensure that the NotificationHandler can michael@0: // access the NotificationManager service. michael@0: mHandler = new NotificationHandler(this) { michael@0: @Override michael@0: protected void setForegroundNotification(int id, Notification notification) { michael@0: super.setForegroundNotification(id, notification); michael@0: michael@0: if (notification == null) { michael@0: stopForeground(true); michael@0: } else { michael@0: startForeground(id, notification); michael@0: } michael@0: } michael@0: }; michael@0: } michael@0: michael@0: public class NotificationBinder extends Binder { michael@0: NotificationService getService() { michael@0: // Return this instance of NotificationService so clients can call public methods michael@0: return NotificationService.this; michael@0: } michael@0: } michael@0: michael@0: @Override michael@0: public IBinder onBind(Intent intent) { michael@0: return mBinder; michael@0: } michael@0: michael@0: public NotificationHandler getNotificationHandler() { michael@0: return mHandler; michael@0: } michael@0: }