Merge "fmapp2: Fix the issue FM recording timer does not stop"
diff --git a/FMRecord/res/drawable/ic_menu_record.png b/FMRecord/res/drawable/ic_menu_record.png
new file mode 100755
index 0000000..60f7a01
--- /dev/null
+++ b/FMRecord/res/drawable/ic_menu_record.png
Binary files differ
diff --git a/FMRecord/res/layout/record_status_bar.xml b/FMRecord/res/layout/record_status_bar.xml
new file mode 100644
index 0000000..d2e1151
--- /dev/null
+++ b/FMRecord/res/layout/record_status_bar.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (c) 2013, 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 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+   android:id="@+id/fmradio"
+   android:layout_width="fill_parent"
+   android:layout_height="fill_parent"
+   android:orientation="vertical">
+
+   <TextView
+       android:id="@+id/record_label"
+       android:layout_width="fill_parent"
+       android:layout_height="wrap_content"
+       android:textSize="15sp"
+       android:text="@string/fm_record_progress"/>
+
+</RelativeLayout>
diff --git a/FMRecord/res/values/strings.xml b/FMRecord/res/values/strings.xml
index 59f14ad..ff11d19 100644
--- a/FMRecord/res/values/strings.xml
+++ b/FMRecord/res/values/strings.xml
@@ -46,4 +46,5 @@
     <!-- all recordings will show up in the media database in a playlist with this name -->
     <string name="audio_db_playlist_name">FM recordings</string>
     <string name="save_record_file">FM Recorded file saved to "<xliff:g id="record_file">%1$s</xliff:g>"</string>
+    <string name="fm_record_progress">FM Recording in progress</string>
 </resources>
diff --git a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
index 2c615e8..39db48a 100644
--- a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
+++ b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
@@ -57,6 +57,13 @@
 import android.net.Uri;
 import android.content.res.Resources;
 import android.os.StatFs;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.widget.RemoteViews;
+import android.R.layout;
+import android.R.drawable;
+import android.content.ComponentName;
+import android.content.res.Resources;
 
 public class FMRecordingService extends Service {
     private static final String TAG     = "FMRecordingService";
@@ -282,9 +289,19 @@
         });
         mSampleStart = System.currentTimeMillis();
         sendRecordingStatusIntent(START);
+        startNotification();
         return true;
     }
 
+    private void startNotification() {
+        RemoteViews views = new RemoteViews(getPackageName(), R.layout.record_status_bar);
+        Notification status = new Notification();
+        status.contentView = views;
+        status.flags |= Notification.FLAG_ONGOING_EVENT;
+        status.icon = R.drawable.ic_menu_record;
+        startForeground(102, status);
+    }
+
     private void stopRecord() {
         Log.d(TAG, "Enter stopRecord");
         mFmRecordingOn = false;
@@ -301,6 +318,7 @@
 
         sendRecordingStatusIntent(STOP);
         saveFile();
+        stopForeground(true);
     }
 
     private void saveFile() {