Consolidate onResume* and onPause* in modules.

1. Combine onResumeAfterSuper() and onResumeBeforeSuper() to resume().
2. Combine onPauseAfterSuper() and onPauseBeforeSuper() to pause().
3. Add helper function requestBackCamera() to CameraModule.

Change-Id: Ie0ffb0168e2df1e77aba4ead4f8729eca09c894a
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index cf9f024..468ec7b 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -363,8 +363,8 @@
     /**
      * Constructs a new photo module.
      */
-    public PhotoModule(CameraServices services) {
-        super(services);
+    public PhotoModule(AppController app) {
+        super(app);
     }
 
     @Override
@@ -1181,33 +1181,6 @@
         return mFirstTimeInitialized;
     }
 
-    @Override
-    public void onResumeBeforeSuper() {
-        mPaused = false;
-    }
-
-    @Override
-    public void onResumeAfterSuper() {
-        // Add delay on resume from lock screen only, in order to to speed up
-        // the onResume --> onPause --> onResume cycle from lock screen.
-        // Don't do always because letting go of thread can cause delay.
-        String action = mActivity.getIntent().getAction();
-        if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(action)
-                || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)) {
-            Log.v(TAG, "On resume, from lock screen.");
-            // Note: onPauseAfterSuper() will delete this runnable, so we will
-            // at most have 1 copy queued up.
-            mHandler.postDelayed(new Runnable() {
-                public void run() {
-                    onResumeTasks();
-                }
-            }, ON_RESUME_TASKS_DELAY_MSEC);
-        } else {
-            Log.v(TAG, "On resume.");
-            onResumeTasks();
-        }
-    }
-
     private void onResumeTasks() {
         Log.v(TAG, "Executing onResumeTasks.");
         if (mOpenCameraFail || mCameraDisabled) return;
@@ -1245,13 +1218,57 @@
         }
     }
 
-    @Override
-    public void onPauseAfterSuper() {
+    /**
+     * The focus manager is the first UI related element to get initialized,
+     * and it requires the RenderOverlay, so initialize it here
+     */
+    private void initializeFocusManager() {
+        // Create FocusManager object. startPreview needs it.
+        // if mFocusManager not null, reuse it
+        // otherwise create a new instance
+        if (mFocusManager != null) {
+            mFocusManager.removeMessages();
+        } else {
+            CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+            mMirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
+            String[] defaultFocusModes = mActivity.getResources().getStringArray(
+                    R.array.pref_camera_focusmode_default_array);
+            mFocusManager = new FocusOverlayManager(mPreferences, defaultFocusModes,
+                    mInitialParams, this, mMirror,
+                    mActivity.getMainLooper(), mUI);
+        }
     }
 
     @Override
-    public void onPauseBeforeSuper() {
-        Log.v(TAG, "On pause.");
+    public void init(AppController app, boolean isSecureCamera, boolean isCaptureIntent) {
+        init((CameraActivity) app.getAndroidContext(), app.getModuleLayoutRoot());
+    }
+
+    @Override
+    public void resume() {
+        mPaused = false;
+        // Add delay on resume from lock screen only, in order to to speed up
+        // the onResume --> onPause --> onResume cycle from lock screen.
+        // Don't do always because letting go of thread can cause delay.
+        String action = mActivity.getIntent().getAction();
+        if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(action)
+                || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)) {
+            Log.v(TAG, "On resume, from lock screen.");
+            // Note: onPauseAfterSuper() will delete this runnable, so we will
+            // at most have 1 copy queued up.
+            mHandler.postDelayed(new Runnable() {
+                public void run() {
+                    onResumeTasks();
+                }
+            }, ON_RESUME_TASKS_DELAY_MSEC);
+        } else {
+            Log.v(TAG, "On resume.");
+            onResumeTasks();
+        }
+    }
+
+    @Override
+    public void pause() {
         mPaused = true;
         Sensor gsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
         if (gsensor != null) {
@@ -1299,44 +1316,6 @@
         mUI.removeDisplayChangeListener();
     }
 
-    /**
-     * The focus manager is the first UI related element to get initialized,
-     * and it requires the RenderOverlay, so initialize it here
-     */
-    private void initializeFocusManager() {
-        // Create FocusManager object. startPreview needs it.
-        // if mFocusManager not null, reuse it
-        // otherwise create a new instance
-        if (mFocusManager != null) {
-            mFocusManager.removeMessages();
-        } else {
-            CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
-            mMirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
-            String[] defaultFocusModes = mActivity.getResources().getStringArray(
-                    R.array.pref_camera_focusmode_default_array);
-            mFocusManager = new FocusOverlayManager(mPreferences, defaultFocusModes,
-                    mInitialParams, this, mMirror,
-                    mActivity.getMainLooper(), mUI);
-        }
-    }
-
-    @Override
-    public void init(AppController app, boolean isSecureCamera, boolean isCaptureIntent) {
-        init((CameraActivity) app.getAndroidContext(), app.getModuleLayoutRoot());
-    }
-
-    @Override
-    public void resume() {
-        onResumeBeforeSuper();
-        onResumeAfterSuper();
-    }
-
-    @Override
-    public void pause() {
-        onPauseBeforeSuper();
-        onPauseAfterSuper();
-    }
-
     @Override
     public void destroy() {
         // TODO: implement this.