• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dialer.precall;
18 
19 import android.app.Activity;
20 import android.support.annotation.MainThread;
21 import android.support.annotation.NonNull;
22 import android.support.annotation.VisibleForTesting;
23 import com.android.dialer.callintent.CallIntentBuilder;
24 import com.android.dialer.function.Consumer;
25 import com.google.common.util.concurrent.ListenableFuture;
26 
27 /**
28  * Runs {@link PreCallAction} one by one to prepare a {@link
29  * com.android.dialer.callintent.CallIntentBuilder} for a call.
30  */
31 public interface PreCallCoordinator {
32 
33   @VisibleForTesting public String EXTRA_CALL_INTENT_BUILDER = "extra_call_intent_builder";
34 
35   @NonNull
getBuilder()36   CallIntentBuilder getBuilder();
37 
38   /** @return the activity to attach the UI to. */
39   @NonNull
getActivity()40   Activity getActivity();
41 
42   /**
43    * Called by a {@link PreCallAction} to abort the call. For example, the user has dismissed the
44    * dialog and must start over.
45    */
abortCall()46   void abortCall();
47 
48   /**
49    * Callback from a {@link PreCallAction} to signal the action started by {@link
50    * PreCallCoordinator#startPendingAction()} has finished.
51    */
52   interface PendingAction {
53 
54     @MainThread
finish()55     void finish();
56   }
57 
58   /**
59    * Called by the current running {@link PreCallAction} to release the main thread and resume
60    * pre-call later.
61    *
62    * @return a {@link PendingAction} which {@link PendingAction#finish()} should be called to resume
63    *     pre-call. For example the action shows a dialog to the user, startPendingAction() should be
64    *     called as the action will not be finished immediately. When the dialog is completed, {@code
65    *     finish()} is then called to continue the next step.
66    */
67   @MainThread
68   @NonNull
startPendingAction()69   PendingAction startPendingAction();
70 
listen( ListenableFuture<OutputT> future, Consumer<OutputT> successListener, Consumer<Throwable> failureListener)71   <OutputT> void listen(
72       ListenableFuture<OutputT> future,
73       Consumer<OutputT> successListener,
74       Consumer<Throwable> failureListener);
75 }
76