1 /*
2  * Copyright (C) 2016 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.callcomposer;
18 
19 import android.content.Context;
20 import android.support.annotation.Nullable;
21 import android.support.v4.app.Fragment;
22 import com.android.dialer.common.Assert;
23 import com.android.dialer.common.FragmentUtils;
24 import com.android.dialer.common.LogUtil;
25 
26 /** Base fragment with fields and methods needed for all fragments in the call compose UI. */
27 public abstract class CallComposerFragment extends Fragment {
28 
29   protected static final int CAMERA_PERMISSION = 1;
30   protected static final int STORAGE_PERMISSION = 2;
31 
32   @Override
onAttach(Context context)33   public void onAttach(Context context) {
34     super.onAttach(context);
35     if (FragmentUtils.getParent(this, CallComposerListener.class) == null) {
36       LogUtil.e(
37           "CallComposerFragment.onAttach",
38           "Container activity must implement CallComposerListener.");
39       Assert.fail();
40     }
41   }
42 
43   @Nullable
getListener()44   public CallComposerListener getListener() {
45     return FragmentUtils.getParent(this, CallComposerListener.class);
46   }
47 
shouldHide()48   public abstract boolean shouldHide();
49 
clearComposer()50   public abstract void clearComposer();
51 
52   /** Interface used to listen to CallComposeFragments */
53   public interface CallComposerListener {
54     /** Let the listener know when a call is ready to be composed. */
composeCall(CallComposerFragment fragment)55     void composeCall(CallComposerFragment fragment);
56 
57     /** Let the listener know when the layout has changed to full screen */
showFullscreen(boolean show)58     void showFullscreen(boolean show);
59 
60     /** True is the listener is in fullscreen. */
isFullscreen()61     boolean isFullscreen();
62 
63     /** True if the layout is in landscape mode. */
isLandscapeLayout()64     boolean isLandscapeLayout();
65 
66     /** Tell the listener that call composition is done and we should start the call. */
sendAndCall()67     void sendAndCall();
68   }
69 }
70