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.processing;
18 
19 import android.content.Context;
20 import android.location.Location;
21 
22 import com.android.camera.app.CameraServices;
23 import com.android.camera.session.CaptureSession;
24 
25 /**
26  * An interface for tasks to be processed by a {@code ProcessingService}.
27  */
28 public interface ProcessingTask {
29     /**
30      * The result returned by a {@code ProcessingTask}.
31      */
32     public class ProcessingResult {
33         public final boolean mSuccess;
34         public final CaptureSession mSession;
35 
36         /**
37          * @param success whether the processing was successful.
38          * @param session the capture session for the processed task.
39          */
ProcessingResult(boolean success, CaptureSession session)40         public ProcessingResult(boolean success, CaptureSession session) {
41             mSuccess = success;
42             mSession = session;
43         }
44     }
45 
46     /**
47      * Classes implementing this interface can be informed when a task is done
48      * processing.
49      */
50     public interface ProcessingTaskDoneListener {
51         /**
52          * Called when a task is done processing.
53          *
54          * @param result the processing result.
55          */
onDone(ProcessingResult result)56         public void onDone(ProcessingResult result);
57     }
58 
59     /**
60      * Processes the given task. This will be usually called by a service.
61      *
62      * @param context the caller {@code Context}
63      * @param services the available {@code CameraServices}
64      * @param session the {@code CaptureSession}
65      * @return the {@code ProcessResult} with the result of the processing
66      */
process(Context context, CameraServices services, CaptureSession session)67     public ProcessingResult process(Context context, CameraServices services,
68             CaptureSession session);
69 
70     /**
71      * Suspend the task whenever possible. There is no guarantee that the task
72      * will pause right away or at all.
73      */
suspend()74     public void suspend();
75 
76     /**
77      * Resume the task if it has been suspended before.
78      */
resume()79     public void resume();
80 
81     /**
82      * @return the name of the task. It can be null to indicate that the task
83      *         has no name.
84      */
getName()85     public String getName();
86 
87     /**
88      * @return The location of the media that is to be processed. Returns null,
89      *         if no location is available.
90      */
getLocation()91     public Location getLocation();
92 
93     /**
94      * @return The CaptureSession if it has been created, or null.
95      */
getSession()96     public CaptureSession getSession();
97 
98     /** Sets a listener that is informed when this task is done processing. */
setDoneListener(ProcessingTaskDoneListener listener)99     public void setDoneListener(ProcessingTaskDoneListener listener);
100 }
101