OSDN Git Service

Clean up and fix notifications.
authorSascha Haeberling <haeberling@google.com>
Fri, 13 Dec 2013 04:11:09 +0000 (20:11 -0800)
committerSascha Haeberling <haeberling@google.com>
Fri, 13 Dec 2013 04:17:09 +0000 (20:17 -0800)
This fixes the issue where mutliple processes didn't properly create
their own notifications.
This also fixes the wording and messages for the notifications, which
are now always shown.

Change-Id: I829a80c8457e08fd6a3838393ef1080ef5fed433

res/values/strings.xml
src/com/android/camera/app/CameraApp.java
src/com/android/camera/session/CaptureSessionManagerImpl.java
src/com/android/camera/session/ProcessingNotificationManager.java

index 8bfaa7d..88a713b 100644 (file)
     <!-- The content of a dialog showing trimming in progress. [CHAR LIMIT=30] -->
     <string name="please_wait">Please wait</string>
 
-    <!-- Text to show with progress bar while stitching a photo sphere. 'Photo sphere' is a product name. [CHAR LIMIT=35]-->
-    <string name="rendering_photo_sphere">Rendering photo sphere</string>
-
     <!-- title for the dialog showing the error of camera hardware -->
     <string name="camera_error_title">Camera error</string>
 
@@ -720,7 +717,7 @@ CHAR LIMIT=NONE] -->
 
     <!-- Default for camera startup module index -->
     <string name="pref_camera_startup_index_default" translatable="false">0</string>
-    
-    <!-- A message shown to the user, indicating that a media item is being processed. [CHAR LIMIT=25] -->
-    <string name="processing">Processing &#8230;</string>
+
+    <!-- A message shown to the user, indicating that an HDR+ photo is being processed. [CHAR LIMIT=25] -->
+    <string name="processing_hdr_plus">Processing HDR+ &#8230;</string>
  </resources>
index 808bdce..07cd322 100644 (file)
@@ -26,7 +26,6 @@ import com.android.camera.session.PlaceholderManager;
 import com.android.camera.session.ProcessingNotificationManager;
 import com.android.camera.util.CameraUtil;
 import com.android.camera.util.UsageStatistics;
-import com.android.camera2.R;
 
 /**
  * The Camera application class containing important services and functionality
@@ -49,10 +48,8 @@ public class CameraApp extends Application implements CameraServices {
         mMediaSaver = new MediaSaverImpl();
         mNotificationManager = new ProcessingNotificationManager(this);
         mPlaceHolderManager = new PlaceholderManager(context);
-        CharSequence defaultProgressMessage = getText(R.string.processing);
-
         mSessionManager = new CaptureSessionManagerImpl(mMediaSaver, getContentResolver(),
-                mNotificationManager, mPlaceHolderManager, defaultProgressMessage);
+                mNotificationManager, mPlaceHolderManager);
         mMemoryManager = MemoryManagerImpl.create(getApplicationContext(), mMediaSaver);
     }
 
index 4230393..76cabcc 100644 (file)
@@ -53,7 +53,6 @@ public class CaptureSessionManagerImpl implements CaptureSessionManager {
 
         private CaptureSessionImpl(String title) {
             mTitle = title;
-            mProgressMessage = mDefaultProgressMessage;
         }
 
         @Override
@@ -171,7 +170,6 @@ public class CaptureSessionManagerImpl implements CaptureSessionManager {
     private final ProcessingNotificationManager mNotificationManager;
     private final PlaceholderManager mPlaceholderManager;
     private final ContentResolver mContentResolver;
-    private final CharSequence mDefaultProgressMessage;
 
     /**
      * We use this to fire events to the session listeners from the main thread.
@@ -193,18 +191,15 @@ public class CaptureSessionManagerImpl implements CaptureSessionManager {
      *            progress
      * @param placeholderManager used to manage placeholders in the filmstrip
      *            before the final result is ready
-     * @param defaultProgressMessage message shown as the current progress
-     *            status by default
      */
     public CaptureSessionManagerImpl(MediaSaver mediaSaver,
             ContentResolver contentResolver, ProcessingNotificationManager notificationManager,
-            PlaceholderManager placeholderManager, CharSequence defaultProgressMessage) {
+            PlaceholderManager placeholderManager) {
         mSessions = new HashMap<String, CaptureSession>();
         mMediaSaver = mediaSaver;
         mContentResolver = contentResolver;
         mNotificationManager = notificationManager;
         mPlaceholderManager = placeholderManager;
-        mDefaultProgressMessage = defaultProgressMessage;
     }
 
     @Override
index 0bbca9a..df1ca64 100644 (file)
@@ -21,6 +21,7 @@ import android.app.Notification;
 import android.app.NotificationManager;
 import android.content.Context;
 import android.os.Build;
+import android.util.SparseArray;
 
 import com.android.camera2.R;
 
@@ -56,7 +57,8 @@ public class ProcessingNotificationManager {
 
     private final Context mContext;
     private final NotificationManager mNotificationManager;
-    private Notification.Builder mInProgressNotificationBuilder;
+    private final SparseArray<Notification.Builder> mNotificationBuilders =
+            new SparseArray<Notification.Builder>();
 
     /**
      * Creates a new {@code ProcessingNotificationManager} with a
@@ -77,12 +79,12 @@ public class ProcessingNotificationManager {
      * @return whether the update was successful
      */
     public boolean setProgress(int progress, int notificationId) {
-        if (mInProgressNotificationBuilder == null) {
+        Notification.Builder builder = mNotificationBuilders.get(notificationId);
+        if (builder == null) {
             return false;
         }
-        mInProgressNotificationBuilder.setProgress(100, progress, false);
-        mNotificationManager.notify(
-                notificationId, buildNotification(mInProgressNotificationBuilder));
+        builder.setProgress(100, progress, false);
+        mNotificationManager.notify(notificationId, buildNotification(builder));
         return true;
     }
 
@@ -91,12 +93,12 @@ public class ProcessingNotificationManager {
      * @return whether the update was successful
      */
     public boolean setStatus(CharSequence status, int notificationId) {
-        if (mInProgressNotificationBuilder == null) {
+        Notification.Builder builder = mNotificationBuilders.get(notificationId);
+        if (builder == null) {
             return false;
         }
-        mInProgressNotificationBuilder.setContentText(status);
-        mNotificationManager.notify(
-                notificationId, buildNotification(mInProgressNotificationBuilder));
+        builder.setContentText(status);
+        mNotificationManager.notify(notificationId, buildNotification(builder));
         return true;
     }
 
@@ -109,15 +111,13 @@ public class ProcessingNotificationManager {
      * @return The ID of the notification.
      */
     public int notifyStart(CharSequence statusMessage) {
-        if (mInProgressNotificationBuilder != null) {
-            return -1;
-        }
-        mInProgressNotificationBuilder = createInProgressNotificationBuilder(statusMessage);
+        Notification.Builder builder = createInProgressNotificationBuilder(statusMessage);
         // Increment the global notification id to make sure we have a unique
         // id.
         int notificationId = sUniqueNotificationId.incrementAndGet();
+        mNotificationBuilders.put(notificationId, builder);
         mNotificationManager.notify(
-                notificationId, buildNotification(mInProgressNotificationBuilder));
+                notificationId, buildNotification(builder));
         return notificationId;
     }
 
@@ -126,11 +126,12 @@ public class ProcessingNotificationManager {
      * notification.
      */
     public void notifyCompletion(int notificationId) {
-        if (mInProgressNotificationBuilder == null) {
+        Notification.Builder builder = mNotificationBuilders.get(notificationId);
+        if (builder == null) {
             return;
         }
         mNotificationManager.cancel(notificationId);
-        mInProgressNotificationBuilder = null;
+        builder = null;
     }
 
     /**
@@ -138,11 +139,12 @@ public class ProcessingNotificationManager {
      * left intact.
      */
     public void cancel(int notificationId) {
-        if (mInProgressNotificationBuilder == null) {
+        Notification.Builder builder = mNotificationBuilders.get(notificationId);
+        if (builder == null) {
             return;
         }
         mNotificationManager.cancel(notificationId);
-        mInProgressNotificationBuilder = null;
+        builder = null;
     }
 
     /**
@@ -158,7 +160,7 @@ public class ProcessingNotificationManager {
                 .setOngoing(true)
                 .setContentTitle(mContext.getText(R.string.app_name))
                 .setProgress(100, 0, false)
-                .setTicker(statusMessage);
+                .setContentText(statusMessage);
     }
 
     @SuppressLint("NewApi")