diff options
Diffstat (limited to 'InCallUI')
-rw-r--r-- | InCallUI/src/com/android/incallui/Call.java | 6 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallButtonFragment.java | 89 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallButtonPresenter.java | 115 |
3 files changed, 167 insertions, 43 deletions
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java index 830b58114..f3986a4fa 100644 --- a/InCallUI/src/com/android/incallui/Call.java +++ b/InCallUI/src/com/android/incallui/Call.java @@ -327,8 +327,12 @@ public final class Call { return mParentCallId; } + public int getVideoState() { + return mTelecommCall.getDetails().getVideoState(); + } + public boolean isVideoCall() { - int videoState = mTelecommCall.getDetails().getVideoState(); + int videoState = getVideoState(); return (videoState & VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL) == VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL; } diff --git a/InCallUI/src/com/android/incallui/CallButtonFragment.java b/InCallUI/src/com/android/incallui/CallButtonFragment.java index 077c8124b..80119a404 100644 --- a/InCallUI/src/com/android/incallui/CallButtonFragment.java +++ b/InCallUI/src/com/android/incallui/CallButtonFragment.java @@ -68,8 +68,7 @@ public class CallButtonFragment @Override CallButtonPresenter createPresenter() { - // TODO: find a cleaner way to include audio mode provider than - // having a singleton instance. + // TODO: find a cleaner way to include audio mode provider than having a singleton instance. return new CallButtonPresenter(); } @@ -91,50 +90,20 @@ public class CallButtonFragment mExtraRowButton = parent.findViewById(R.id.extraButtonRow); mManageConferenceButton = parent.findViewById(R.id.manageConferenceButton); - mManageConferenceButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - getPresenter().manageConferenceButtonClicked(); - } - }); + mManageConferenceButton.setOnClickListener(this); mGenericMergeButton = parent.findViewById(R.id.cdmaMergeButton); - mGenericMergeButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - getPresenter().mergeClicked(); - } - }); - - mMuteButton = (ImageButton) parent.findViewById(R.id.muteButton); - mMuteButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - final ImageButton button = (ImageButton) v; - getPresenter().muteClicked(!button.isSelected()); - } - }); + mGenericMergeButton.setOnClickListener(this); mAudioButton = (ImageButton) parent.findViewById(R.id.audioButton); - mAudioButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - onAudioButtonClicked(); - } - }); - - mHoldButton = (ImageButton) parent.findViewById(R.id.holdButton); - mHoldButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - final ImageButton button = (ImageButton) v; - getPresenter().holdClicked(!button.isSelected()); - } - }); - + mAudioButton.setOnClickListener(this); mChangeToVoiceButton = (ImageButton) parent.findViewById(R.id.changeToVoiceButton); mChangeToVoiceButton. setOnClickListener(this); + mMuteButton = (ImageButton) parent.findViewById(R.id.muteButton); + mMuteButton.setOnClickListener(this); mShowDialpadButton = (ImageButton) parent.findViewById(R.id.dialpadButton); mShowDialpadButton.setOnClickListener(this); + mHoldButton = (ImageButton) parent.findViewById(R.id.holdButton); + mHoldButton.setOnClickListener(this); mSwapButton = (ImageButton) parent.findViewById(R.id.swapButton); mSwapButton.setOnClickListener(this); mChangeToVideoButton = (ImageButton) parent.findViewById(R.id.changeToVideoButton); @@ -159,6 +128,7 @@ public class CallButtonFragment // set the buttons updateAudioButtons(getPresenter().getSupportedAudio()); + getPresenter().initializeCameraManager(getActivity().getApplicationContext()); } @Override @@ -179,24 +149,51 @@ public class CallButtonFragment Log.d(this, "onClick(View " + view + ", id " + id + ")..."); switch(id) { + case R.id.audioButton: + onAudioButtonClicked(); + break; case R.id.addButton: getPresenter().addCallClicked(); break; + case R.id.changeToVoiceButton: + getPresenter().changeToVoiceClicked(); + break; + case R.id.muteButton: { + final ImageButton button = (ImageButton) view; + getPresenter().muteClicked(!button.isSelected()); + break; + } + case R.id.cdmaMergeButton: case R.id.mergeButton: getPresenter().mergeClicked(); break; + case R.id.holdButton: { + final ImageButton button = (ImageButton) view; + getPresenter().holdClicked(!button.isSelected()); + break; + } case R.id.swapButton: getPresenter().swapClicked(); break; case R.id.dialpadButton: getPresenter().showDialpadClicked(!mShowDialpadButton.isSelected()); break; - case R.id.changeToVoiceButton: case R.id.changeToVideoButton: + getPresenter().changeToVideoClicked(); + break; case R.id.switchCameraButton: + getPresenter().switchCameraClicked( + mSwitchCameraButton.isSelected() /* useFrontFacingCamera */); + break; case R.id.pauseVideoButton: + getPresenter().pauseVideoClicked( + !mPauseVideoButton.isSelected() /* pause */); + break; case R.id.overflowButton: - // TODO: Implement these button behaviors. + // TODO: Implement. + break; + case R.id.manageConferenceButton: + getPresenter().manageConferenceButtonClicked(); break; default: Log.wtf(this, "onClick: unexpected"); @@ -282,6 +279,11 @@ public class CallButtonFragment } @Override + public void setSwitchCameraButton(boolean isBackFacingCamera) { + mSwitchCameraButton.setSelected(isBackFacingCamera); + } + + @Override public void showAddCallButton(boolean show) { mAddCallButton.setVisibility(show ? View.VISIBLE : View.GONE); } @@ -302,6 +304,11 @@ public class CallButtonFragment } @Override + public void setPauseVideoButton(boolean isPaused) { + mPauseVideoButton.setSelected(isPaused); + } + + @Override public void showOverflowButton(boolean show) { mOverflowButton.setVisibility(show ? View.VISIBLE : View.GONE); } diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java index 4f457b8c2..6e841a1cc 100644 --- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java +++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java @@ -16,7 +16,13 @@ package com.android.incallui; +import android.content.Context; +import android.hardware.camera2.CameraAccessException; +import android.hardware.camera2.CameraCharacteristics; +import android.hardware.camera2.CameraManager; import android.telecomm.CallCapabilities; +import android.telecomm.RemoteCallVideoProvider; +import android.telecomm.VideoCallProfile; import com.android.contacts.common.util.PhoneNumberHelper; import com.android.contacts.common.util.TelephonyManagerUtils; @@ -37,15 +43,20 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto private Call mCall; private boolean mAutomaticallyMuted = false; private boolean mPreviousMuteState = false; - private boolean mShowGenericMerge = false; private boolean mShowManageConference = false; + private boolean mUseFrontFacingCamera = true; private InCallState mPreviousState = null; + private CameraManager mCameraManager; public CallButtonPresenter() { } + public void initializeCameraManager(Context context) { + mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); + } + @Override public void onUiReady(CallButtonUi ui) { super.onUiReady(ui); @@ -201,6 +212,17 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto TelecommAdapter.getInstance().addCall(); } + public void changeToVoiceClicked() { + RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider(); + if (callVideoProvider == null) { + return; + } + + VideoCallProfile videoCallProfile = new VideoCallProfile( + VideoCallProfile.VIDEO_STATE_AUDIO_ONLY, VideoCallProfile.QUALITY_DEFAULT); + callVideoProvider.sendSessionModifyRequest(videoCallProfile); + } + public void swapClicked() { TelecommAdapter.getInstance().swap(mCall.getId()); } @@ -211,6 +233,62 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto updateExtraButtonRow(); } + public void changeToVideoClicked() { + RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider(); + if (callVideoProvider == null) { + return; + } + + VideoCallProfile videoCallProfile = + new VideoCallProfile(VideoCallProfile.VIDEO_STATE_BIDIRECTIONAL); + callVideoProvider.sendSessionModifyRequest(videoCallProfile); + } + + /** + * Switches the camera between the front-facing and back-facing camera. + * @param useFrontFacingCamera True if we should switch to using the front-facing camera, or + * false if we should switch to using the back-facing camera. + */ + public void switchCameraClicked(boolean useFrontFacingCamera) { + mUseFrontFacingCamera = useFrontFacingCamera; + + RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider(); + if (callVideoProvider == null) { + return; + } + + String cameraId = getCameraId(); + if (cameraId != null) { + callVideoProvider.setCamera(cameraId); + } + getUi().setSwitchCameraButton(!useFrontFacingCamera); + } + + /** + * Stop or start client's video transmission. + * @param pause True if pausing the local user's video, or false if starting the local user's + * video. + */ + public void pauseVideoClicked(boolean pause) { + RemoteCallVideoProvider callVideoProvider = mCall.getCallVideoProvider(); + if (callVideoProvider == null) { + return; + } + + if (pause) { + callVideoProvider.setCamera(null); + VideoCallProfile videoCallProfile = new VideoCallProfile( + mCall.getVideoState() | VideoCallProfile.VIDEO_STATE_PAUSED); + callVideoProvider.sendSessionModifyRequest(videoCallProfile); + } else { + callVideoProvider.setCamera(getCameraId()); + VideoCallProfile videoCallProfile = new VideoCallProfile( + mCall.getVideoState() & ~VideoCallProfile.VIDEO_STATE_PAUSED); + callVideoProvider.sendSessionModifyRequest(videoCallProfile); + } + getUi().setPauseVideoButton(pause); + } + private void updateUi(InCallState state, Call call) { Log.d(this, "Updating call UI for call: ", call); @@ -343,6 +421,39 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto } } + private String getCameraId() { + String[] cameraIds = {}; + String cameraId = null; + int targetCharacteristic = mUseFrontFacingCamera + ? CameraCharacteristics.LENS_FACING_FRONT : CameraCharacteristics.LENS_FACING_BACK; + + try { + cameraIds = mCameraManager.getCameraIdList(); + } catch (CameraAccessException e) { + // Camera disabled by device policy. + } + + for (int i = 0; i < cameraIds.length; i++) { + CameraCharacteristics c = null; + try { + c = mCameraManager.getCameraCharacteristics(cameraIds[i]); + } catch (IllegalArgumentException e) { + // Device Id is unknown. + } catch (CameraAccessException e) { + // Camera disabled by device policy. + } + if (c != null) { + int facingCharacteristic = c.get(CameraCharacteristics.LENS_FACING); + if (facingCharacteristic == targetCharacteristic) { + cameraId = cameraIds[i]; + break; + } + } + } + + return cameraId; + } + public void refreshMuteState() { // Restore the previous mute state if (mAutomaticallyMuted && @@ -368,10 +479,12 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto void showSwapButton(boolean show); void showChangeToVideoButton(boolean show); void showSwitchCameraButton(boolean show); + void setSwitchCameraButton(boolean isBackFacingCamera); void showAddCallButton(boolean show); void enableAddCall(boolean enabled); void showMergeButton(boolean show); void showPauseVideoButton(boolean show); + void setPauseVideoButton(boolean isPaused); void showOverflowButton(boolean show); void displayDialpad(boolean on, boolean animate); boolean isDialpadVisible(); |