public boolean isCameraInitNeeded() {
   if (DBG) {
     log(
         "isCameraInitNeeded mCameraNeeded="
             + mCameraNeeded
             + " mCameraSurface= "
             + mCameraSurface
             + " camera state = "
             + mVideoCallManager.getCameraState());
   }
   return mCameraNeeded
       && mCameraSurface != null
       && mVideoCallManager.getCameraState() == CameraState.CAMERA_CLOSED;
 }
  /** This method is called when the visibility of the VideoCallPanel is changed */
  @Override
  protected void onVisibilityChanged(View changedView, int visibility) {
    if (changedView != this || mVideoCallManager == null) {
      return;
    }

    switch (visibility) {
      case View.INVISIBLE:
      case View.GONE:
        if (DBG) log("VideoCallPanel View is GONE or INVISIBLE");
        // Stop the preview and close the camera now because other
        // activities may need to use it
        if (mVideoCallManager.getCameraState() != CameraState.CAMERA_CLOSED) {
          stopRecordingAndPreview();
          closeCamera();
        }
        break;
      case View.VISIBLE:
        if (DBG) log("VideoCallPanel View is VISIBLE");
        if (isCameraInitNeeded()) {
          initializeCamera();
        }
        break;
    }
  }
  /**
   * This method switches the camera to front/back or off
   *
   * @param cameraId
   */
  private void switchCamera(int cameraId) {
    // Change the camera Id
    mCameraId = cameraId;

    // Stop camera preview if already running
    if (mVideoCallManager.getCameraState() != CameraState.CAMERA_CLOSED) {
      stopRecordingAndPreview();
      closeCamera();
    }

    // Restart camera if camera doesn't need to stay off
    if (isCameraInitNeeded()) {
      initializeCamera();
    }
  }
 public void setPanelElementsVisibility(int callType) {
   switch (callType) {
     case Phone.CALL_TYPE_VT:
       if (isCameraInitNeeded()) {
         initializeCamera();
       }
       break;
     case Phone.CALL_TYPE_VT_TX:
       if (isCameraInitNeeded()) {
         initializeCamera();
       }
       break;
     case Phone.CALL_TYPE_VT_RX:
       // Stop the preview and close the camera now because other
       // activities may need to use it
       if (mVideoCallManager.getCameraState() != CameraState.CAMERA_CLOSED) {
         stopRecordingAndPreview();
         closeCamera();
       }
       break;
     default:
       log("setPanelElementsVisibility: callType=" + callType);
       break;
   }
   log(
       "setPanelElementsVisibility: callType= "
           + callType
           + " VideoCallPanel is "
           + mVideoCallPanel.getVisibility()
           + " mCameraPreview is "
           + mCameraPreview.getVisibility()
           + " available="
           + mCameraPreview.isAvailable()
           + " activated= "
           + mCameraPreview.isActivated()
           + " mFarEndView is "
           + mFarEndView.getVisibility()
           + " available="
           + mFarEndView.isAvailable()
           + " activated= "
           + mFarEndView.isActivated());
 }