• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.incallui.video.impl;
18 
19 import android.support.annotation.NonNull;
20 import android.support.annotation.Nullable;
21 import android.view.View;
22 import android.view.View.OnClickListener;
23 import com.android.dialer.common.Assert;
24 import com.android.incallui.incall.protocol.InCallScreenDelegate;
25 import com.android.incallui.incall.protocol.SecondaryInfo;
26 import com.android.incallui.video.protocol.VideoCallScreenDelegate;
27 
28 /** Manages the swap button and on hold banner. */
29 public class SwitchOnHoldCallController implements OnClickListener {
30 
31   @NonNull private InCallScreenDelegate inCallScreenDelegate;
32   @NonNull private VideoCallScreenDelegate videoCallScreenDelegate;
33 
34   @NonNull private View switchOnHoldButton;
35 
36   @NonNull private View onHoldBanner;
37 
38   private boolean isVisible;
39 
40   private boolean isEnabled;
41 
42   @Nullable private SecondaryInfo secondaryInfo;
43 
SwitchOnHoldCallController( @onNull View switchOnHoldButton, @NonNull View onHoldBanner, @NonNull InCallScreenDelegate inCallScreenDelegate, @NonNull VideoCallScreenDelegate videoCallScreenDelegate)44   public SwitchOnHoldCallController(
45       @NonNull View switchOnHoldButton,
46       @NonNull View onHoldBanner,
47       @NonNull InCallScreenDelegate inCallScreenDelegate,
48       @NonNull VideoCallScreenDelegate videoCallScreenDelegate) {
49     this.switchOnHoldButton = Assert.isNotNull(switchOnHoldButton);
50     switchOnHoldButton.setOnClickListener(this);
51     this.onHoldBanner = Assert.isNotNull(onHoldBanner);
52     this.inCallScreenDelegate = Assert.isNotNull(inCallScreenDelegate);
53     this.videoCallScreenDelegate = Assert.isNotNull(videoCallScreenDelegate);
54   }
55 
setEnabled(boolean isEnabled)56   public void setEnabled(boolean isEnabled) {
57     this.isEnabled = isEnabled;
58     updateButtonState();
59   }
60 
setVisible(boolean isVisible)61   public void setVisible(boolean isVisible) {
62     this.isVisible = isVisible;
63     updateButtonState();
64   }
65 
setOnScreen()66   public void setOnScreen() {
67     isVisible = hasSecondaryInfo();
68     updateButtonState();
69   }
70 
setSecondaryInfo(@ullable SecondaryInfo secondaryInfo)71   public void setSecondaryInfo(@Nullable SecondaryInfo secondaryInfo) {
72     this.secondaryInfo = secondaryInfo;
73     isVisible = hasSecondaryInfo();
74   }
75 
hasSecondaryInfo()76   private boolean hasSecondaryInfo() {
77     return secondaryInfo != null && secondaryInfo.shouldShow();
78   }
79 
updateButtonState()80   public void updateButtonState() {
81     switchOnHoldButton.setEnabled(isEnabled);
82     switchOnHoldButton.setVisibility(isVisible ? View.VISIBLE : View.INVISIBLE);
83     onHoldBanner.setVisibility(isVisible ? View.VISIBLE : View.INVISIBLE);
84   }
85 
86   @Override
onClick(View view)87   public void onClick(View view) {
88     inCallScreenDelegate.onSecondaryInfoClicked();
89     videoCallScreenDelegate.resetAutoFullscreenTimer();
90   }
91 }
92