Merge "Actually remove settings" into ub-camera-glacier
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 112eb43..43cddd2 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -251,6 +251,9 @@
     private Menu mActionBarMenu;
     private Preloader<Integer, AsyncTask> mPreloader;
 
+    /** Can be used to play custom sounds. */
+    private SoundPlayer mSoundPlayer;
+
     private static final int LIGHTS_OUT_DELAY_MS = 4000;
     private final int BASE_SYS_UI_VISIBILITY =
         View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
@@ -283,7 +286,7 @@
         }
     };
 
-    private ActionBar.OnMenuVisibilityListener mOnMenuVisibilityListener =
+    private final ActionBar.OnMenuVisibilityListener mOnMenuVisibilityListener =
             new ActionBar.OnMenuVisibilityListener() {
         @Override
         public void onMenuVisibilityChanged(boolean isVisible) {
@@ -1317,6 +1320,7 @@
 
         mOnCreateTime = System.currentTimeMillis();
         mAppContext = getApplicationContext();
+        mSoundPlayer = new SoundPlayer(mAppContext);
 
         // TODO: Try to move all the resources allocation to happen as soon as
         // possible so we can call module.init() at the earliest time.
@@ -1855,6 +1859,7 @@
         mButtonManager = null;
         CameraAgentFactory.recycle(CameraAgentFactory.CameraApi.API_1);
         CameraAgentFactory.recycle(CameraAgentFactory.CameraApi.AUTO);
+        mSoundPlayer.release();
         super.onDestroy();
     }
 
@@ -2175,6 +2180,11 @@
         return mButtonManager;
     }
 
+    @Override
+    public SoundPlayer getSoundPlayer() {
+        return mSoundPlayer;
+    }
+
     /**
      * Creates an AlertDialog appropriate for choosing whether to enable
      * location on the first run of the app.
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 011ecf1..497eb9a 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -266,12 +266,6 @@
     private final File mDebugDataDir;
 
     /** CLEAN UP START */
-    // private SoundPool mSoundPool;
-    // private int mCaptureStartSoundId;
-    // private static final int NO_SOUND_STREAM = -999;
-    // private final int mCaptureStartSoundStreamId = NO_SOUND_STREAM;
-    // private int mCaptureDoneSoundId;
-    // private SoundClips.Player mSoundPlayer;
     // private boolean mFirstLayout;
     // private int[] mTargetFPSRanges;
     // private float mZoomValue;
diff --git a/src/com/android/camera/FocusOverlayManager.java b/src/com/android/camera/FocusOverlayManager.java
index f345908..682c3ab 100644
--- a/src/com/android/camera/FocusOverlayManager.java
+++ b/src/com/android/camera/FocusOverlayManager.java
@@ -566,7 +566,7 @@
                 // autoFocus call is not required.
                 mUI.onFocusStarted();
             }
-        } else if (mState == STATE_FOCUSING || mState == STATE_FOCUSING_SNAP_ON_FINISH) {
+        } else if (mState == STATE_FOCUSING) {
             mUI.onFocusStarted();
         } else {
             if (mFocusMode == CameraCapabilities.FocusMode.CONTINUOUS_PICTURE) {
diff --git a/src/com/android/camera/SoundPlayer.java b/src/com/android/camera/SoundPlayer.java
new file mode 100644
index 0000000..3f17c58
--- /dev/null
+++ b/src/com/android/camera/SoundPlayer.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera;
+
+import android.content.Context;
+import android.media.SoundPool;
+import android.util.SparseIntArray;
+
+/**
+ * Loads a plays custom sounds. For playing system-standard sounds for various
+ * camera actions, please refer to {@link SoundClips}.
+ */
+public class SoundPlayer {
+    private final Context mAppContext;
+    private final SoundPool mSoundPool;
+    /** Keeps a mapping from sound resource ID to sound ID */
+    private final SparseIntArray mResourceToSoundId = new SparseIntArray();
+
+    /**
+     * Construct a new sound player.
+     */
+    public SoundPlayer(Context appContext) {
+        mAppContext = appContext;
+        final int audioType = SoundClips.getAudioTypeForSoundPool();
+        mSoundPool = new SoundPool(1 /* max streams */, audioType, 0 /* quality */);
+    }
+
+    /**
+     * Load the sound from a resource.
+     */
+    public void loadSound(int resourceId) {
+        int soundId = mSoundPool.load(mAppContext, resourceId, 1/* priority */);
+        mResourceToSoundId.put(resourceId, soundId);
+    }
+
+    /**
+     * Play the sound with the given resource. The resource has to be loaded
+     * before it can be played, otherwise an exception will be thrown.
+     */
+    public void play(int resourceId, float volume) {
+        Integer soundId = mResourceToSoundId.get(resourceId);
+        if (soundId == null) {
+            throw new IllegalStateException("Sound not loaded. Must call #loadSound first.");
+        }
+        mSoundPool.play(soundId, volume, volume, 0 /* priority */, 0 /* loop */, 1 /* rate */);
+    }
+
+    /**
+     * Unload the given sound if it's not needed anymore to release memory.
+     */
+    public void unloadSound(int resourceId) {
+        Integer soundId = mResourceToSoundId.get(resourceId);
+        if (soundId == null) {
+            throw new IllegalStateException("Sound not loaded. Must call #loadSound first.");
+        }
+        mSoundPool.unload(soundId);
+    }
+
+    /**
+     * Call this if you don't need the SoundPlayer anymore. All memory will be
+     * released and the object cannot be re-used.
+     */
+    public void release() {
+        mSoundPool.release();
+    }
+}
diff --git a/src/com/android/camera/app/AppController.java b/src/com/android/camera/app/AppController.java
index e09ff4d..f273914 100644
--- a/src/com/android/camera/app/AppController.java
+++ b/src/com/android/camera/app/AppController.java
@@ -28,6 +28,7 @@
 import android.widget.FrameLayout;
 
 import com.android.camera.ButtonManager;
+import com.android.camera.SoundPlayer;
 import com.android.camera.module.ModuleController;
 import com.android.camera.one.OneCameraManager;
 import com.android.camera.settings.SettingsManager;
@@ -367,6 +368,9 @@
      */
     public ButtonManager getButtonManager();
 
+    /** Returns a sound player that can be used to play custom sounds. */
+    public SoundPlayer getSoundPlayer();
+
     /** Whether auto-rotate is enabled.*/
     public boolean isAutoRotateScreen();
 
diff --git a/src/com/android/camera/one/OneCameraManager.java b/src/com/android/camera/one/OneCameraManager.java
index dc83d14..4a4ed6e 100644
--- a/src/com/android/camera/one/OneCameraManager.java
+++ b/src/com/android/camera/one/OneCameraManager.java
@@ -88,7 +88,7 @@
                 .getMaxAllowedNativeMemoryAllocation();
         if (cameraManager != null && isCamera2Supported(cameraManager)) {
             return new com.android.camera.one.v2.OneCameraManagerImpl(cameraManager, maxMemoryMB,
-                    displayMetrics);
+                    displayMetrics, activity.getSoundPlayer());
         } else {
             return new com.android.camera.one.v1.OneCameraManagerImpl();
         }
diff --git a/src/com/android/camera/one/v2/OneCameraManagerImpl.java b/src/com/android/camera/one/v2/OneCameraManagerImpl.java
index c9ef115..07112e5 100644
--- a/src/com/android/camera/one/v2/OneCameraManagerImpl.java
+++ b/src/com/android/camera/one/v2/OneCameraManagerImpl.java
@@ -22,6 +22,7 @@
 import android.hardware.camera2.CameraManager;
 import android.util.DisplayMetrics;
 
+import com.android.camera.SoundPlayer;
 import com.android.camera.debug.Log;
 import com.android.camera.debug.Log.Tag;
 import com.android.camera.one.OneCamera;
@@ -38,6 +39,7 @@
     private final CameraManager mCameraManager;
     private final int mMaxMemoryMB;
     private final DisplayMetrics mDisplayMetrics;
+    private final SoundPlayer mSoundPlayer;
 
     /**
      * Instantiates a new {@link OneCameraManager} for Camera2 API.
@@ -47,10 +49,11 @@
      *            during capture and processing, in megabytes.
      */
     public OneCameraManagerImpl(CameraManager cameraManager, int maxMemoryMB,
-            DisplayMetrics displayMetrics) {
+            DisplayMetrics displayMetrics, SoundPlayer soundPlayer) {
         mCameraManager = cameraManager;
         mMaxMemoryMB = maxMemoryMB;
         mDisplayMetrics = displayMetrics;
+        mSoundPlayer = soundPlayer;
     }
 
     @Override
@@ -78,7 +81,8 @@
                                 .getCameraCharacteristics(device.getId());
                         // TODO: Set boolean based on whether HDR+ is enabled.
                         OneCamera oneCamera = OneCameraCreator.create(useHdr, device,
-                                characteristics, pictureSize, mMaxMemoryMB, mDisplayMetrics);
+                                characteristics, pictureSize, mMaxMemoryMB, mDisplayMetrics,
+                                mSoundPlayer);
                         openCallback.onCameraOpened(oneCamera);
                     } catch (CameraAccessException e) {
                         Log.d(TAG, "Could not get camera characteristics");
diff --git a/src_pd/com/android/camera/one/v2/OneCameraCreator.java b/src_pd/com/android/camera/one/v2/OneCameraCreator.java
index 790c17e..4720663 100644
--- a/src_pd/com/android/camera/one/v2/OneCameraCreator.java
+++ b/src_pd/com/android/camera/one/v2/OneCameraCreator.java
@@ -20,13 +20,14 @@
 import android.hardware.camera2.CameraDevice;
 import android.util.DisplayMetrics;
 
+import com.android.camera.SoundPlayer;
 import com.android.camera.one.OneCamera;
 import com.android.camera.util.Size;
 
 public class OneCameraCreator {
     public static OneCamera create(boolean useHdr, CameraDevice device,
             CameraCharacteristics characteristics, Size pictureSize, int maxMemoryMB,
-            DisplayMetrics displayMetrics) {
+            DisplayMetrics displayMetrics, SoundPlayer soundPlayer) {
         // TODO: Might want to switch current camera to vendor HDR.
         return new OneCameraImpl(device, characteristics, pictureSize);
     }