Home | History | Annotate | Download | only in apprtc
      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 View controlView;
     30   private TextView contactView;
     31   private ImageButton disconnectButton;
     32   private ImageButton cameraSwitchButton;
     33   private ImageButton videoScalingButton;
     34   private TextView captureFormatText;
     35   private SeekBar captureFormatSlider;
     36   private OnCallEvents callEvents;
     37   private ScalingType scalingType;
     38   private boolean videoCallEnabled = true;
     39 
     40   /**
     41    * Call control interface for container activity.
     42    */
     43   public interface OnCallEvents {
     44     public void onCallHangUp();
     45     public void onCameraSwitch();
     46     public void onVideoScalingSwitch(ScalingType scalingType);
     47     public void onCaptureFormatChange(int width, int height, int framerate);
     48   }
     49 
     50   @Override
     51   public View onCreateView(LayoutInflater inflater, ViewGroup container,
     52       Bundle savedInstanceState) {
     53     controlView =
     54         inflater.inflate(R.layout.fragment_call, container, false);
     55 
     56     // Create UI controls.
     57     contactView =
     58         (TextView) controlView.findViewById(R.id.contact_name_call);
     59     disconnectButton =
     60         (ImageButton) controlView.findViewById(R.id.button_call_disconnect);
     61     cameraSwitchButton =
     62         (ImageButton) controlView.findViewById(R.id.button_call_switch_camera);
     63     videoScalingButton =
     64         (ImageButton) controlView.findViewById(R.id.button_call_scaling_mode);
     65     captureFormatText =
     66         (TextView) controlView.findViewById(R.id.capture_format_text_call);
     67     captureFormatSlider =
     68         (SeekBar) controlView.findViewById(R.id.capture_format_slider_call);
     69 
     70     // Add buttons click events.
     71     disconnectButton.setOnClickListener(new View.OnClickListener() {
     72       @Override
     73       public void onClick(View view) {
     74         callEvents.onCallHangUp();
     75       }
     76     });
     77 
     78     cameraSwitchButton.setOnClickListener(new View.OnClickListener() {
     79       @Override
     80       public void onClick(View view) {
     81         callEvents.onCameraSwitch();
     82       }
     83     });
     84 
     85     videoScalingButton.setOnClickListener(new View.OnClickListener() {
     86       @Override
     87       public void onClick(View view) {
     88         if (scalingType == ScalingType.SCALE_ASPECT_FILL) {
     89           videoScalingButton.setBackgroundResource(
     90               R.drawable.ic_action_full_screen);
     91           scalingType = ScalingType.SCALE_ASPECT_FIT;
     92         } else {
     93           videoScalingButton.setBackgroundResource(
     94               R.drawable.ic_action_return_from_full_screen);
     95           scalingType = ScalingType.SCALE_ASPECT_FILL;
     96         }
     97         callEvents.onVideoScalingSwitch(scalingType);
     98       }
     99     });
    100     scalingType = ScalingType.SCALE_ASPECT_FILL;
    101 
    102     return controlView;
    103   }
    104 
    105   @Override
    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   @Override
    131   public void onAttach(Activity activity) {
    132     super.onAttach(activity);
    133     callEvents = (OnCallEvents) activity;
    134   }
    135 
    136 }
    137