diff options
-rw-r--r-- | fmapp2/res/layout/statusbar.xml | 56 | ||||
-rw-r--r-- | fmapp2/res/values/strings.xml | 5 | ||||
-rw-r--r-- | fmapp2/src/com/caf/fmradio/FMRadioService.java | 44 | ||||
-rw-r--r-- | fmapp2/src/com/caf/fmradio/FMTransmitterService.java | 43 |
4 files changed, 51 insertions, 97 deletions
diff --git a/fmapp2/res/layout/statusbar.xml b/fmapp2/res/layout/statusbar.xml deleted file mode 100644 index 47e1a91..0000000 --- a/fmapp2/res/layout/statusbar.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/* - * Copyright (C) 2012, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation, Inc. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - --> - -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:orientation="horizontal"> - - <ImageView android:id="@+id/icon" - android:layout_gravity="center_vertical" - android:paddingLeft="10dp" - android:paddingRight="10dp" - android:layout_width="wrap_content" - android:layout_height="wrap_content"> - </ImageView> - - <TextView android:id="@+id/frequency" - android:textAppearance="?android:attr/textAppearanceMediumInverse" - android:textColor="@android:color/black" - android:focusable="true" - android:ellipsize="marquee" - android:singleLine="true" - android:layout_gravity="center" - android:layout_width="wrap_content" - android:layout_height="wrap_content" /> - -</LinearLayout> diff --git a/fmapp2/res/values/strings.xml b/fmapp2/res/values/strings.xml index 3d490d0..6c4afd6 100644 --- a/fmapp2/res/values/strings.xml +++ b/fmapp2/res/values/strings.xml @@ -84,9 +84,8 @@ <string name="preset_search">Search for "<xliff:g id="preset_pi">%1$s</xliff:g>" </string> - <string name="stat_notif_frequency">FM Radio Station "<xliff:g id="frequency">%1$s</xliff:g>" MHz</string> - <string name="stat_notif_tx_frequency">FM Transmitting at: "<xliff:g id="frequency">%1$s</xliff:g>"</string> - + <string name="stat_notif_frequency">"<xliff:g id="frequency">%1$s</xliff:g>" MHz</string> + <string name="stat_notif_tx_frequency">Transmitting at: "<xliff:g id="frequency">%1$s</xliff:g>"</string> <string name="sel_band_menu">Select Regional Band</string> <string name="test_menu">Select Test</string> diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index 54654fa..f3fb535 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import android.app.AlarmManager; +import android.app.Notification.Builder; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -222,6 +223,10 @@ public class FMRadioService extends Service private static Object mNotchFilterLock = new Object(); + private Notification.Builder mRadioNotification; + private Notification mNotificationInstance; + private NotificationManager mNotificationManager; + public FMRadioService() { } @@ -1690,27 +1695,28 @@ public class FMRadioService extends Service /* Show the FM Notification */ public void startNotification() { - RemoteViews views = new RemoteViews(getPackageName(), R.layout.statusbar); - views.setImageViewResource(R.id.icon, R.drawable.stat_notify_fm); - if (isFmOn()) - { - views.setTextViewText(R.id.frequency, getTunedFrequencyString()); - } else - { - views.setTextViewText(R.id.frequency, ""); + mRadioNotification = new Notification.Builder(this) + .setSmallIcon(R.drawable.stat_notify_fm) + .setOngoing(true) + .setWhen(0); + + PendingIntent resultIntent = PendingIntent.getActivity(this, 0, + new Intent("com.caf.fmradio.FMRADIO_ACTIVITY"), 0); + mRadioNotification.setContentIntent(resultIntent); + + mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); + if (isFmOn()) { + mRadioNotification.setContentTitle(getString(R.string.app_name)) + .setContentText(getTunedFrequencyString()); + } else { + mRadioNotification.setContentTitle("") + .setContentText(""); } + mNotificationInstance = mRadioNotification.getNotification(); + mNotificationManager.notify(FMRADIOSERVICE_STATUS, mNotificationInstance); + + startForeground(FMRADIOSERVICE_STATUS, mNotificationInstance); - Notification status = new Notification(); - status.contentView = views; - status.flags |= Notification.FLAG_ONGOING_EVENT; - status.icon = R.drawable.stat_notify_fm; - status.contentIntent = PendingIntent.getActivity(this, 0, - new Intent("com.caf.fmradio.FMRADIO_ACTIVITY"), 0); - startForeground(FMRADIOSERVICE_STATUS, status); - //NotificationManager nm = (NotificationManager) - // getSystemService(Context.NOTIFICATION_SERVICE); - //nm.notify(FMRADIOSERVICE_STATUS, status); - //setForeground(true); mFMOn = true; } diff --git a/fmapp2/src/com/caf/fmradio/FMTransmitterService.java b/fmapp2/src/com/caf/fmradio/FMTransmitterService.java index e3cf3d6..07362a0 100644 --- a/fmapp2/src/com/caf/fmradio/FMTransmitterService.java +++ b/fmapp2/src/com/caf/fmradio/FMTransmitterService.java @@ -30,6 +30,7 @@ package com.caf.fmradio; import java.lang.ref.WeakReference; +import android.app.Notification.Builder; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -108,6 +109,9 @@ public class FMTransmitterService extends Service // interval after which we stop the service when idle private static final int IDLE_DELAY = 60000; + private Notification.Builder mRadioNotification; + private Notification mNotificationInstance; + private NotificationManager mNotificationManager; private static String RText = " "; private IAudioService mAudioService; private AudioManager mAudioManager; @@ -278,27 +282,28 @@ public class FMTransmitterService extends Service /* Show the FM Notification */ public void startNotification() { - RemoteViews views = new RemoteViews(getPackageName(), R.layout.statusbar); - views.setImageViewResource(R.id.icon, R.drawable.ic_status_fm_tx); - if (isFmOn()) - { - views.setTextViewText(R.id.frequency, getTunedFrequencyString()); - } else - { - views.setTextViewText(R.id.frequency, ""); + mRadioNotification = new Notification.Builder(this) + .setSmallIcon(R.drawable.ic_status_fm_tx) + .setOngoing(true) + .setWhen(0); + + PendingIntent resultIntent = PendingIntent.getActivity(this, 0, + new Intent("com.caf.fmradio.FMTRANSMITTER_ACTIVITY"), 0); + mRadioNotification.setContentIntent(resultIntent); + + mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); + if (isFmOn()) { + mRadioNotification.setContentTitle(getString(R.string.app_name)) + .setContentText(getTunedFrequencyString()); + } else { + mRadioNotification.setContentTitle("") + .setContentText(""); } + mNotificationInstance = mRadioNotification.getNotification(); + mNotificationManager.notify(FMTRANSMITTERSERVICE_STATUS, mNotificationInstance); + + startForeground(FMTRANSMITTERSERVICE_STATUS, mNotificationInstance); - Notification status = new Notification(); - status.contentView = views; - status.flags |= Notification.FLAG_ONGOING_EVENT; - status.icon = R.drawable.ic_status_fm_tx; - status.contentIntent = PendingIntent.getActivity(this, 0, - new Intent("com.caf.fmradio.FMTRANSMITTER_ACTIVITY"), 0); - startForeground(FMTRANSMITTERSERVICE_STATUS, status); - //NotificationManager nm = (NotificationManager) - // getSystemService(Context.NOTIFICATION_SERVICE); - //nm.notify(FMTRANSMITTERSERVICE_STATUS, status); - //setForeground(true); mFMOn = true; } |