summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonsta <konsta09@gmail.com>2013-07-16 19:15:42 +0300
committerEthan Chen <intervigil@gmail.com>2015-01-08 12:30:34 -0800
commit62d6beeb7077cf8458385d9488e22e179eb35aeb (patch)
treee0c50466b3f5b2d887ab61772a20d5f0100a476b
parentea4928fc5c4dde20ae3b290cde2f0ebaff3d9b0f (diff)
downloadandroid_hardware_qcom_fm-62d6beeb7077cf8458385d9488e22e179eb35aeb.tar.gz
android_hardware_qcom_fm-62d6beeb7077cf8458385d9488e22e179eb35aeb.tar.bz2
android_hardware_qcom_fm-62d6beeb7077cf8458385d9488e22e179eb35aeb.zip
FM2: Update notification to use notification builder
Make FM notifications look like something from this decade. :P Change-Id: Ib0e310a320c49e92224d8d4fc2fab530ff28d974
-rw-r--r--fmapp2/res/layout/statusbar.xml56
-rw-r--r--fmapp2/res/values/strings.xml5
-rw-r--r--fmapp2/src/com/caf/fmradio/FMRadioService.java44
-rw-r--r--fmapp2/src/com/caf/fmradio/FMTransmitterService.java43
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 55b2932..cdd0937 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 f643ec3..c6a3854 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;
@@ -184,6 +185,10 @@ public class FMRadioService extends Service
private boolean mIsSSRInProgress = false;
private boolean mIsSSRInProgressFromActivity = false;
+ private Notification.Builder mRadioNotification;
+ private Notification mNotificationInstance;
+ private NotificationManager mNotificationManager;
+
public FMRadioService() {
}
@@ -1357,27 +1362,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 980c968..fd12c35 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;
}