OSDN Git Service

[CaptureIntentModule] Add StateBackgroundWithSurfaceTexture.
authorSenpo Hu <senpo@google.com>
Thu, 26 Feb 2015 22:38:04 +0000 (14:38 -0800)
committerSenpo Hu <senpo@google.com>
Thu, 26 Feb 2015 22:47:58 +0000 (14:47 -0800)
Module is in this state when first run dialog is still presented. The
module will be resumed after people finish first run dialog.

Bug: 19531554
Change-Id: Ibe878eba66ab4f235a39a6d5ba0abfdad30f5cab

src/com/android/camera/captureintent/CaptureIntentModule.java
src/com/android/camera/captureintent/state/State.java
src/com/android/camera/captureintent/state/StateBackground.java
src/com/android/camera/captureintent/state/StateBackgroundWithSurfaceTexture.java [new file with mode: 0644]
src/com/android/camera/captureintent/state/StateForegroundWithSurfaceTexture.java

index 3043a14..fe26485 100644 (file)
@@ -142,13 +142,12 @@ public class CaptureIntentModule extends CameraModule {
     @Override
     public void init(
             final CameraActivity activity, boolean isSecureCamera, boolean isCaptureIntent) {
-        // Do nothing.
+        mAppController.setPreviewStatusListener(mPreviewStatusListener);
     }
 
     @Override
     public void resume() {
         mModuleUI.onModuleResumed();
-        mAppController.setPreviewStatusListener(mPreviewStatusListener);
         mAppController.addPreviewAreaSizeChangedListener(mModuleUI);
         mStateMachine.processEvent(new EventResume());
     }
@@ -157,7 +156,6 @@ public class CaptureIntentModule extends CameraModule {
     public void pause() {
         mModuleUI.setCountdownFinishedListener(null);
         mAppController.removePreviewAreaSizeChangedListener(mModuleUI);
-        mAppController.setPreviewStatusListener(null);
         mModuleUI.onModulePaused();
         mStateMachine.processEvent(new EventPause());
     }
index acf163f..5b21151 100644 (file)
@@ -35,6 +35,7 @@ public abstract class State {
     public static enum ID {
         Uninitialized,
         Background,
+        BackgroundWithSurfaceTexture,
         Fatal,
         Foreground,
         ForegroundWithSurfaceTexture,
index d06d742..eac0733 100644 (file)
@@ -30,6 +30,7 @@ import com.android.camera.settings.ResolutionSetting;
 
 import android.content.Context;
 import android.content.Intent;
+import android.graphics.SurfaceTexture;
 
 /**
  * Represents a state that module is inactive in background. This is also the
@@ -95,4 +96,10 @@ public final class StateBackground extends State {
     public Optional<State> processResume() {
         return Optional.of((State) new StateForeground(this, mResourceConstructed));
     }
+
+    @Override
+    public Optional<State> processOnSurfaceTextureAvailable(SurfaceTexture surfaceTexture) {
+        return Optional.of((State) StateBackgroundWithSurfaceTexture.from(
+                this, mResourceConstructed, surfaceTexture));
+    }
 }
diff --git a/src/com/android/camera/captureintent/state/StateBackgroundWithSurfaceTexture.java b/src/com/android/camera/captureintent/state/StateBackgroundWithSurfaceTexture.java
new file mode 100644 (file)
index 0000000..80ccf34
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2015 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.captureintent.state;
+
+import com.google.common.base.Optional;
+
+import com.android.camera.app.AppController;
+import com.android.camera.async.RefCountBase;
+import com.android.camera.captureintent.PreviewTransformCalculator;
+
+import android.graphics.SurfaceTexture;
+
+/**
+ * Represents a state that module is inactive in background but surface texture
+ * is available.
+ * <p>
+ * Module is in this state when first run dialog is still presented. The module
+ * will be resumed after people finish first run dialog (b/19531554).
+ */
+public class StateBackgroundWithSurfaceTexture extends State {
+    private final RefCountBase<ResourceConstructed> mResourceConstructed;
+    private final RefCountBase<ResourceSurfaceTexture> mResourceSurfaceTexture;
+
+    // Used to transition from Foreground on processOnSurfaceTextureAvailable.
+    public static StateBackgroundWithSurfaceTexture from(
+            StateBackground background,
+            RefCountBase<ResourceConstructed> resourceConstructed,
+            SurfaceTexture surfaceTexture) {
+        return new StateBackgroundWithSurfaceTexture(
+                background,
+                resourceConstructed,
+                surfaceTexture,
+                new PreviewTransformCalculator(resourceConstructed.get().getOrientationManager()),
+                resourceConstructed.get().getAppController());
+    }
+
+    private StateBackgroundWithSurfaceTexture(
+            State previousState,
+            RefCountBase<ResourceConstructed> resourceConstructed,
+            SurfaceTexture surfaceTexture,
+            PreviewTransformCalculator previewTransformCalculator,
+            AppController appController) {
+        super(State.ID.BackgroundWithSurfaceTexture, previousState);
+        mResourceConstructed = resourceConstructed;
+        mResourceConstructed.addRef();     // Will be balanced in onLeave().
+        mResourceSurfaceTexture = ResourceSurfaceTexture.create(
+                surfaceTexture, previewTransformCalculator, appController);
+    }
+
+    @Override
+    public Optional<State> onEnter() {
+        // Do nothing unless the module is resumed.
+        return Optional.absent();
+    }
+
+    @Override
+    public void onLeave() {
+        mResourceConstructed.close();
+        mResourceSurfaceTexture.close();
+    }
+
+    @Override
+    public Optional<State> processResume() {
+        return Optional.of((State) StateForegroundWithSurfaceTexture.from(
+                this, mResourceConstructed, mResourceSurfaceTexture));
+    }
+}
index a185f68..e0ff7a9 100644 (file)
@@ -39,7 +39,7 @@ public final class StateForegroundWithSurfaceTexture extends State {
     private final RefCountBase<ResourceConstructed> mResourceConstructed;
     private final RefCountBase<ResourceSurfaceTexture> mResourceSurfaceTexture;
 
-    // Used to transition from Foreground on processOnSurfaceTextureAvailable.
+    // Used to transition from Foreground on surface texture is available.
     public static StateForegroundWithSurfaceTexture from(
             StateForeground foreground,
             RefCountBase<ResourceConstructed> resourceConstructed,
@@ -52,6 +52,17 @@ public final class StateForegroundWithSurfaceTexture extends State {
                 resourceConstructed.get().getAppController());
     }
 
+    // Used to transition from BackgroundWithSurfaceTexture on module is resumed.
+    public static StateForegroundWithSurfaceTexture from(
+            StateBackgroundWithSurfaceTexture backgroundWithSurfaceTexture,
+            RefCountBase<ResourceConstructed> resourceConstructed,
+            RefCountBase<ResourceSurfaceTexture> resourceSurfaceTexture) {
+        return new StateForegroundWithSurfaceTexture(
+                backgroundWithSurfaceTexture,
+                resourceConstructed,
+                resourceSurfaceTexture);
+    }
+
     private StateForegroundWithSurfaceTexture(
             State previousState,
             RefCountBase<ResourceConstructed> resourceConstructed,
@@ -65,6 +76,17 @@ public final class StateForegroundWithSurfaceTexture extends State {
                 surfaceTexture, previewTransformCalculator, appController);
     }
 
+    private StateForegroundWithSurfaceTexture(
+            State previousState,
+            RefCountBase<ResourceConstructed> resourceConstructed,
+            RefCountBase<ResourceSurfaceTexture> resourceSurfaceTexture) {
+        super(ID.ForegroundWithSurfaceTexture, previousState);
+        mResourceConstructed = resourceConstructed;
+        mResourceConstructed.addRef();     // Will be balanced in onLeave().
+        mResourceSurfaceTexture = resourceSurfaceTexture;
+        mResourceSurfaceTexture.addRef();
+    }
+
     @Override
     public void onLeave() {
         mResourceConstructed.close();