• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2015 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 package org.appspot.apprtc;
12 
13 import android.app.Activity;
14 import android.app.Fragment;
15 import android.os.Bundle;
16 import android.view.LayoutInflater;
17 import android.view.View;
18 import android.view.ViewGroup;
19 import android.widget.ImageButton;
20 import android.widget.SeekBar;
21 import android.widget.TextView;
22 
23 import org.webrtc.RendererCommon.ScalingType;
24 
25 /**
26  * Fragment for call control.
27  */
28 public class CallFragment extends Fragment {
29   private TextView contactView;
30   private ImageButton cameraSwitchButton;
31   private ImageButton videoScalingButton;
32   private ImageButton toggleMuteButton;
33   private TextView captureFormatText;
34   private SeekBar captureFormatSlider;
35   private OnCallEvents callEvents;
36   private ScalingType scalingType;
37   private boolean videoCallEnabled = true;
38 
39   /**
40    * Call control interface for container activity.
41    */
42   public interface OnCallEvents {
onCallHangUp()43     void onCallHangUp();
onCameraSwitch()44     void onCameraSwitch();
onVideoScalingSwitch(ScalingType scalingType)45     void onVideoScalingSwitch(ScalingType scalingType);
onCaptureFormatChange(int width, int height, int framerate)46     void onCaptureFormatChange(int width, int height, int framerate);
onToggleMic()47     boolean onToggleMic();
48   }
49 
50   @Override
onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)51   public View onCreateView(
52       LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
53     View controlView = inflater.inflate(R.layout.fragment_call, container, false);
54 
55     // Create UI controls.
56     contactView = controlView.findViewById(R.id.contact_name_call);
57     ImageButton disconnectButton = controlView.findViewById(R.id.button_call_disconnect);
58     cameraSwitchButton = controlView.findViewById(R.id.button_call_switch_camera);
59     videoScalingButton = controlView.findViewById(R.id.button_call_scaling_mode);
60     toggleMuteButton = controlView.findViewById(R.id.button_call_toggle_mic);
61     captureFormatText = controlView.findViewById(R.id.capture_format_text_call);
62     captureFormatSlider = controlView.findViewById(R.id.capture_format_slider_call);
63 
64     // Add buttons click events.
65     disconnectButton.setOnClickListener(new View.OnClickListener() {
66       @Override
67       public void onClick(View view) {
68         callEvents.onCallHangUp();
69       }
70     });
71 
72     cameraSwitchButton.setOnClickListener(new View.OnClickListener() {
73       @Override
74       public void onClick(View view) {
75         callEvents.onCameraSwitch();
76       }
77     });
78 
79     videoScalingButton.setOnClickListener(new View.OnClickListener() {
80       @Override
81       public void onClick(View view) {
82         if (scalingType == ScalingType.SCALE_ASPECT_FILL) {
83           videoScalingButton.setBackgroundResource(R.drawable.ic_action_full_screen);
84           scalingType = ScalingType.SCALE_ASPECT_FIT;
85         } else {
86           videoScalingButton.setBackgroundResource(R.drawable.ic_action_return_from_full_screen);
87           scalingType = ScalingType.SCALE_ASPECT_FILL;
88         }
89         callEvents.onVideoScalingSwitch(scalingType);
90       }
91     });
92     scalingType = ScalingType.SCALE_ASPECT_FILL;
93 
94     toggleMuteButton.setOnClickListener(new View.OnClickListener() {
95       @Override
96       public void onClick(View view) {
97         boolean enabled = callEvents.onToggleMic();
98         toggleMuteButton.setAlpha(enabled ? 1.0f : 0.3f);
99       }
100     });
101 
102     return controlView;
103   }
104 
105   @Override
onStart()106   public void onStart() {
107     super.onStart();
108 
109     boolean captureSliderEnabled = false;
110     Bundle args = getArguments();
111     if (args != null) {
112       String contactName = args.getString(CallActivity.EXTRA_ROOMID);
113       contactView.setText(contactName);
114       videoCallEnabled = args.getBoolean(CallActivity.EXTRA_VIDEO_CALL, true);
115       captureSliderEnabled = videoCallEnabled
116           && args.getBoolean(CallActivity.EXTRA_VIDEO_CAPTUREQUALITYSLIDER_ENABLED, false);
117     }
118     if (!videoCallEnabled) {
119       cameraSwitchButton.setVisibility(View.INVISIBLE);
120     }
121     if (captureSliderEnabled) {
122       captureFormatSlider.setOnSeekBarChangeListener(
123           new CaptureQualityController(captureFormatText, callEvents));
124     } else {
125       captureFormatText.setVisibility(View.GONE);
126       captureFormatSlider.setVisibility(View.GONE);
127     }
128   }
129 
130   // TODO(sakal): Replace with onAttach(Context) once we only support API level 23+.
131   @SuppressWarnings("deprecation")
132   @Override
onAttach(Activity activity)133   public void onAttach(Activity activity) {
134     super.onAttach(activity);
135     callEvents = (OnCallEvents) activity;
136   }
137 }
138