use of android.view.SurfaceView in project vlc-android by videolan.
the class VideoPlayerActivity method changeSurfaceLayout.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void changeSurfaceLayout() {
int sw;
int sh;
// get screen size
if (mDisplayManager.isPrimary()) {
sw = getWindow().getDecorView().getWidth();
sh = getWindow().getDecorView().getHeight();
} else if (mDisplayManager.getPresentation() != null) {
sw = mDisplayManager.getPresentation().getWindow().getDecorView().getWidth();
sh = mDisplayManager.getPresentation().getWindow().getDecorView().getHeight();
} else
return;
// sanity check
if (sw * sh == 0) {
Log.e(TAG, "Invalid surface size");
return;
}
if (mService != null) {
final IVLCVout vlcVout = mService.getVLCVout();
vlcVout.setWindowSize(sw, sh);
}
SurfaceView surface;
SurfaceView subtitlesSurface;
FrameLayout surfaceFrame;
if (mDisplayManager.isPrimary()) {
surface = mSurfaceView;
subtitlesSurface = mSubtitlesSurfaceView;
surfaceFrame = mSurfaceFrame;
} else if (mDisplayManager.getDisplayType() == DisplayManager.DisplayType.PRESENTATION) {
surface = mDisplayManager.getPresentation().getSurfaceView();
subtitlesSurface = mDisplayManager.getPresentation().getSubtitlesSurfaceView();
surfaceFrame = mDisplayManager.getPresentation().getSurfaceFrame();
} else
return;
LayoutParams lp = surface.getLayoutParams();
if (mVideoWidth * mVideoHeight == 0 || isInPictureInPictureMode()) {
/* Case of OpenGL vouts: handles the placement of the video using MediaPlayer API */
lp.width = LayoutParams.MATCH_PARENT;
lp.height = LayoutParams.MATCH_PARENT;
surface.setLayoutParams(lp);
lp = surfaceFrame.getLayoutParams();
lp.width = LayoutParams.MATCH_PARENT;
lp.height = LayoutParams.MATCH_PARENT;
surfaceFrame.setLayoutParams(lp);
if (mService != null && mVideoWidth * mVideoHeight == 0)
changeMediaPlayerLayout(sw, sh);
return;
}
if (mService != null && lp.width == lp.height && lp.width == LayoutParams.MATCH_PARENT) {
/* We handle the placement of the video using Android View LayoutParams */
mService.setVideoAspectRatio(null);
mService.setVideoScale(0);
}
double dw = sw, dh = sh;
boolean isPortrait;
// getWindow().getDecorView() doesn't always take orientation into account, we have to correct the values
isPortrait = mDisplayManager.isPrimary() && mCurrentScreenOrientation == Configuration.ORIENTATION_PORTRAIT;
if (sw > sh && isPortrait || sw < sh && !isPortrait) {
dw = sh;
dh = sw;
}
// compute the aspect ratio
double ar, vw;
if (mSarDen == mSarNum) {
/* No indication about the density, assuming 1:1 */
vw = mVideoVisibleWidth;
ar = (double) mVideoVisibleWidth / (double) mVideoVisibleHeight;
} else {
/* Use the specified aspect ratio */
vw = mVideoVisibleWidth * (double) mSarNum / mSarDen;
ar = vw / mVideoVisibleHeight;
}
// compute the display aspect ratio
double dar = dw / dh;
switch(mCurrentSize) {
case SURFACE_BEST_FIT:
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_FIT_SCREEN:
if (dar >= ar)
dh = dw / ar;
else
/* horizontal */
dw = dh * ar;
/* vertical */
break;
case SURFACE_FILL:
break;
case SURFACE_16_9:
ar = 16.0 / 9.0;
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_4_3:
ar = 4.0 / 3.0;
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_ORIGINAL:
dh = mVideoVisibleHeight;
dw = vw;
break;
}
// set display size
lp.width = (int) Math.ceil(dw * mVideoWidth / mVideoVisibleWidth);
lp.height = (int) Math.ceil(dh * mVideoHeight / mVideoVisibleHeight);
surface.setLayoutParams(lp);
subtitlesSurface.setLayoutParams(lp);
// set frame size (crop if necessary)
lp = surfaceFrame.getLayoutParams();
lp.width = (int) Math.floor(dw);
lp.height = (int) Math.floor(dh);
surfaceFrame.setLayoutParams(lp);
surface.invalidate();
subtitlesSurface.invalidate();
}
use of android.view.SurfaceView in project weiui by kuaifan.
the class PageActivity method onResume.
@Override
public void onResume() {
super.onResume();
if (mWXSDKInstance != null) {
mWXSDKInstance.onActivityResume();
}
if (scan_containter != null) {
SurfaceView surfaceView = findViewById(R.id.scan_preview);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
if (scan_hasSurface) {
// Camera初始化
initScanerCodeCamera(surfaceHolder);
} else {
surfaceHolder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (!scan_hasSurface) {
scan_hasSurface = true;
initScanerCodeCamera(holder);
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
scan_hasSurface = false;
}
});
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
}
}
use of android.view.SurfaceView in project android_packages_apps_Dialer by LineageOS.
the class SurfaceViewVideoCallFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
LogUtil.i("SurfaceViewVideoCallFragment.onCreateView", null);
View view = layoutInflater.inflate(R.layout.frag_videocall_surfaceview, viewGroup, false);
contactGridManager = new ContactGridManager(view, null, /* no avatar */
0, false);
controls = view.findViewById(R.id.videocall_video_controls);
controls.setVisibility(ActivityCompat.isInMultiWindowMode(getActivity()) ? View.GONE : View.VISIBLE);
controlsContainer = view.findViewById(R.id.videocall_video_controls_container);
speakerButton = (CheckableImageButton) view.findViewById(R.id.videocall_speaker_button);
muteButton = (CheckableImageButton) view.findViewById(R.id.videocall_mute_button);
muteButton.setOnCheckedChangeListener(this);
mutePreviewOverlay = view.findViewById(R.id.videocall_video_preview_mute_overlay);
cameraOffButton = (CheckableImageButton) view.findViewById(R.id.videocall_mute_video);
cameraOffButton.setOnCheckedChangeListener(this);
previewOffOverlay = view.findViewById(R.id.videocall_video_preview_off_overlay);
swapCameraButton = (ImageButton) view.findViewById(R.id.videocall_switch_video);
swapCameraButton.setOnClickListener(this);
view.findViewById(R.id.videocall_switch_controls).setVisibility(ActivityCompat.isInMultiWindowMode(getActivity()) ? View.GONE : View.VISIBLE);
switchOnHoldButton = view.findViewById(R.id.videocall_switch_on_hold);
onHoldContainer = view.findViewById(R.id.videocall_on_hold_banner);
remoteVideoOff = (TextView) view.findViewById(R.id.videocall_remote_video_off);
remoteVideoOff.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
endCallButton = view.findViewById(R.id.videocall_end_call);
endCallButton.setOnClickListener(this);
previewSurfaceView = (SurfaceView) view.findViewById(R.id.videocall_video_preview);
previewSurfaceView.setZOrderMediaOverlay(true);
previewOffOverlay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
checkCameraPermission();
}
});
remoteSurfaceView = (SurfaceView) view.findViewById(R.id.videocall_video_remote);
remoteSurfaceView.setOnClickListener(surfaceView -> {
videoCallScreenDelegate.resetAutoFullscreenTimer();
if (isInFullscreenMode) {
updateFullscreenAndGreenScreenMode(false, /* shouldShowFullscreen */
false);
} else {
updateFullscreenAndGreenScreenMode(true, /* shouldShowFullscreen */
false);
}
});
greenScreenBackgroundView = view.findViewById(R.id.videocall_green_screen_background);
fullscreenBackgroundView = view.findViewById(R.id.videocall_fullscreen_background);
previewRoot = (FrameLayout) view.findViewById(R.id.videocall_preview_root);
// We need the texture view size to be able to scale the remote video. At this point the view
// layout won't be complete so add a layout listener.
ViewTreeObserver observer = remoteSurfaceView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LogUtil.i("SurfaceViewVideoCallFragment.onGlobalLayout", null);
updateVideoOffViews();
// Remove the listener so we don't continually re-layout.
ViewTreeObserver observer = remoteSurfaceView.getViewTreeObserver();
if (observer.isAlive()) {
observer.removeOnGlobalLayoutListener(this);
}
}
});
return view;
}
use of android.view.SurfaceView in project SmartMesh_Android by SmartMeshFoundation.
the class CaptureActivity method onPause.
@Override
protected void onPause() {
if (handler != null) {
handler.quitSynchronously();
handler = null;
}
inactivityTimer.onPause();
ambientLightManager.stop();
cameraManager.closeDriver();
if (!hasSurface) {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.removeCallback(this);
}
super.onPause();
}
use of android.view.SurfaceView in project SmartMesh_Android by SmartMeshFoundation.
the class CaptureActivity method onResume.
@SuppressWarnings("deprecation")
@Override
protected void onResume() {
super.onResume();
cameraManager = new CameraManager(getApplication());
viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
viewfinderView.setCameraManager(cameraManager);
handler = null;
resetStatusView();
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
if (hasSurface) {
initCamera(surfaceHolder);
} else {
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
beepManager.updatePrefs();
ambientLightManager.start(cameraManager);
inactivityTimer.onResume();
decodeFormats = null;
characterSet = null;
}
Aggregations