1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.camera.burst; 18 19 import android.content.Context; 20 import android.graphics.SurfaceTexture; 21 import android.view.Surface; 22 import android.widget.Toast; 23 24 import com.android.camera.app.OrientationManager.DeviceOrientation; 25 import com.android.camera.one.OneCamera.Facing; 26 import com.android.camera.session.CaptureSession; 27 28 /** 29 * A simple decorator for a {@link BurstFacade} that shows toasts for when a 30 * burst starts or stops. 31 * <p> 32 * This class can simply be removed once we have proper UI for this. 33 */ 34 public class ToastingBurstFacadeDecorator implements BurstFacade { 35 36 /** Shows burst-related toasts to the user. */ 37 public static class BurstToaster { 38 private final Context mContext; 39 40 public BurstToaster(Context context) { 41 mContext = context; 42 } 43 44 public void showToastBurstStarted() { 45 Toast.makeText(mContext, MSG_BURST_STARTED, Toast.LENGTH_SHORT).show(); 46 } 47 48 public void showToastBurstStopped() { 49 Toast.makeText(mContext, MSG_BURST_STOPPED, Toast.LENGTH_SHORT).show(); 50 } 51 } 52 53 private static final String MSG_BURST_STARTED = 54 "Keep capture button pressed for duration of burst."; 55 private static final String MSG_BURST_STOPPED = 56 "Burst stopped. Please wait a few seconds for the results to appear."; 57 58 private final BurstFacade mBurstFacade; 59 private final BurstToaster mToaster; 60 61 /** 62 * Initialize the toasting burst facade decorator. 63 * 64 * @param facadeToDecorate the facade to decorate. 65 * @param toaster the toaster to use to show toasts about the burst status. 66 */ 67 public ToastingBurstFacadeDecorator(BurstFacade facadeToDecorate, BurstToaster toaster) { 68 mBurstFacade = facadeToDecorate; 69 mToaster = toaster; 70 } 71 72 @Override 73 public void startBurst(CaptureSession.CaptureSessionCreator captureSessionCreator, 74 DeviceOrientation deviceOrientation, Facing cameraFacing, int imageOrientationDegrees) { 75 mToaster.showToastBurstStarted(); 76 mBurstFacade.startBurst(captureSessionCreator, deviceOrientation, cameraFacing, 77 imageOrientationDegrees); 78 } 79 80 81 @Override 82 public boolean stopBurst() { 83 boolean burstStopped = mBurstFacade.stopBurst(); 84 85 // Only show the toast if a burst was actually stopped. 86 if (burstStopped) { 87 mToaster.showToastBurstStopped(); 88 } 89 return burstStopped; 90 } 91 92 @Override 93 public void initialize(SurfaceTexture surfaceTexture) { 94 mBurstFacade.initialize(surfaceTexture); 95 } 96 97 @Override 98 public void release() { 99 mBurstFacade.release(); 100 } 101 102 @Override 103 public Surface getInputSurface() { 104 return mBurstFacade.getInputSurface(); 105 } 106 107 @Override 108 public void setBurstTaker(BurstTaker burstTaker) { 109 mBurstFacade.setBurstTaker(burstTaker); 110 } 111 } 112