Java Code Examples for android.view.SurfaceView#setLayoutParams()
The following examples show how to use
android.view.SurfaceView#setLayoutParams() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From habpanelviewer with GNU General Public License v3.0 | 6 votes |
public void updateMotionPreferences() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); if (mCam != null) { mCam.updateFromPreferences(prefs); } if (mMotionDetector != null) { mMotionDetector.updateFromPreferences(prefs); } SurfaceView motionView = findViewById(R.id.motionView); boolean showPreview = prefs.getBoolean(Constants.PREF_MOTION_DETECTION_PREVIEW, false); if (showPreview && mCam != null && mCam.canBeUsed()) { ViewGroup.LayoutParams params = motionView.getLayoutParams(); params.height = 480; params.width = 640; motionView.setLayoutParams(params); motionView.setVisibility(View.VISIBLE); } else { motionView.setVisibility(View.INVISIBLE); } }
Example 2
Source File: CameraTakeActivity.java From Android with MIT License | 6 votes |
@Override public void granted(String[] permissions) { surfaceView = new SurfaceView(mActivity); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); surfaceView.setLayoutParams(layoutParams); surfaceViewRela.removeAllViews(); surfaceViewRela.addView(surfaceView); viewHolder = surfaceView.getHolder(); viewHolder.addCallback(new SurfaceCallback()); viewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); surfaceViewRela.setBackgroundColor(mActivity.getResources().getColor(R.color.color_clear)); videoBtn.setEnabled(true); videoBtn.setOnTouchStatusListence(statusListence); }
Example 3
Source File: CameraPreviewfFragment.java From CoolSignIn with Apache License 2.0 | 6 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { camerasurface = (SurfaceView) view.findViewById(R.id.camera_preview); mask = (FaceMask) view.findViewById(R.id.mask); RelativeLayout.LayoutParams para = new RelativeLayout.LayoutParams(480, 800); handleThread = new HandlerThread("dt"); handleThread.start(); detectHandler = new Handler(handleThread.getLooper()); para.addRule(RelativeLayout.CENTER_IN_PARENT); camerasurface.setLayoutParams(para); mask.setLayoutParams(para); camerasurface.getHolder().addCallback(this); camerasurface.setKeepScreenOn(true); facedetecter = new FaceDetecter(); if (!facedetecter.init(getActivity(), "2af33a8a684f670a9c5fcc83afb7d0ca")) { Log.e("diff", "有错误 "); } facedetecter.setTrackingMode(true); }
Example 4
Source File: RegisterPhotoActivity.java From Android with MIT License | 5 votes |
@Override public void granted(String[] permissions) { surfaceView = new SurfaceView(mActivity); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); surfaceView.setLayoutParams(layoutParams); surfaceViewRela.removeAllViews(); surfaceViewRela.addView(surfaceView); viewHolder = surfaceView.getHolder(); viewHolder.addCallback(new SurfaceCallback()); viewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
Example 5
Source File: TakeVideoActivity.java From MultiMediaSample with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { //全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //应用运行时,保持屏幕高亮,不锁屏 super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_take_video); //获取控件 surfaceView = (SurfaceView) findViewById(R.id.surfaceview); recordButton = (Button) findViewById(R.id.btn_start_record); unRecordButton = (Button) findViewById(R.id.btn_stop_record); previewButton = (Button) findViewById(R.id.btn_preview); recordButton.setOnClickListener(this); unRecordButton.setOnClickListener(this); previewButton.setOnClickListener(this); timeSecondView = (TextView) findViewById(R.id.time); curTimeView = (TextView) findViewById(R.id.tv_time); progressBar = (ProgressBar) findViewById(R.id.progressBar); progressBar.setMax(MaxDuring); SurfaceHolder holder = surfaceView.getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); startTime(); //获取支持480p视频 initSupportProfile(); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); //保持预览和视频长宽比一致,不拉伸压缩失真 surfaceView.setLayoutParams(new FrameLayout.LayoutParams(-1, mVideoHeiht * dm.widthPixels / mVideoWidth, Gravity.TOP)); fileCachePath = getIntent().getStringExtra("fileCachePath"); }
Example 6
Source File: RTSPPlayerActivity.java From DeviceConnect-Android with MIT License | 5 votes |
private void changePlayerSize(int pictureWidth, int pictureHeight) { View root = findViewById(R.id.root); SurfaceView surfaceView = findViewById(R.id.surface_view); Size changeSize; Size viewSize = new Size(root.getWidth(), root.getHeight()); changeSize = calculateViewSize(pictureWidth, pictureHeight, viewSize); ViewGroup.LayoutParams layoutParams = surfaceView.getLayoutParams(); layoutParams.width = changeSize.getWidth(); layoutParams.height = changeSize.getHeight(); surfaceView.setLayoutParams(layoutParams); }
Example 7
Source File: SRTPlayerActivity.java From DeviceConnect-Android with MIT License | 5 votes |
private void changePlayerSize(int pictureWidth, int pictureHeight) { View root = findViewById(R.id.root); SurfaceView surfaceView = findViewById(R.id.surface_view); Size changeSize; Size viewSize = new Size(root.getWidth(), root.getHeight()); changeSize = calculateViewSize(pictureWidth, pictureHeight, viewSize); ViewGroup.LayoutParams layoutParams = surfaceView.getLayoutParams(); layoutParams.width = changeSize.getWidth(); layoutParams.height = changeSize.getHeight(); surfaceView.setLayoutParams(layoutParams); }
Example 8
Source File: CodeScannerView.java From code-scanner with MIT License | 4 votes |
private void initialize(@NonNull final Context context, @Nullable final AttributeSet attrs, @AttrRes final int defStyleAttr, @StyleRes final int defStyleRes) { mPreviewView = new SurfaceView(context); mPreviewView.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mViewFinderView = new ViewFinderView(context); mViewFinderView.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); final float density = context.getResources().getDisplayMetrics().density; mButtonSize = Math.round(density * BUTTON_SIZE_DP); mFocusAreaSize = Math.round(density * FOCUS_AREA_SIZE_DP); mAutoFocusButton = new ImageView(context); mAutoFocusButton.setLayoutParams(new LayoutParams(mButtonSize, mButtonSize)); mAutoFocusButton.setScaleType(ImageView.ScaleType.CENTER); mAutoFocusButton.setImageResource(R.drawable.ic_code_scanner_auto_focus_on); mAutoFocusButton.setOnClickListener(new AutoFocusClickListener()); mFlashButton = new ImageView(context); mFlashButton.setLayoutParams(new LayoutParams(mButtonSize, mButtonSize)); mFlashButton.setScaleType(ImageView.ScaleType.CENTER); mFlashButton.setImageResource(R.drawable.ic_code_scanner_flash_on); mFlashButton.setOnClickListener(new FlashClickListener()); if (attrs == null) { mViewFinderView.setFrameAspectRatio(DEFAULT_FRAME_ASPECT_RATIO_WIDTH, DEFAULT_FRAME_ASPECT_RATIO_HEIGHT); mViewFinderView.setMaskColor(DEFAULT_MASK_COLOR); mViewFinderView.setFrameColor(DEFAULT_FRAME_COLOR); mViewFinderView.setFrameThickness(Math.round(DEFAULT_FRAME_THICKNESS_DP * density)); mViewFinderView.setFrameCornersSize(Math.round(DEFAULT_FRAME_CORNER_SIZE_DP * density)); mViewFinderView .setFrameCornersRadius(Math.round(DEFAULT_FRAME_CORNERS_RADIUS_DP * density)); mViewFinderView.setFrameSize(DEFAULT_FRAME_SIZE); mAutoFocusButton.setColorFilter(DEFAULT_AUTO_FOCUS_BUTTON_COLOR); mFlashButton.setColorFilter(DEFAULT_FLASH_BUTTON_COLOR); mAutoFocusButton.setVisibility(DEFAULT_AUTO_FOCUS_BUTTON_VISIBILITY); mFlashButton.setVisibility(DEFAULT_FLASH_BUTTON_VISIBILITY); } else { TypedArray a = null; try { a = context.getTheme() .obtainStyledAttributes(attrs, R.styleable.CodeScannerView, defStyleAttr, defStyleRes); setMaskColor(a.getColor(R.styleable.CodeScannerView_maskColor, DEFAULT_MASK_COLOR)); setFrameColor( a.getColor(R.styleable.CodeScannerView_frameColor, DEFAULT_FRAME_COLOR)); setFrameThickness( a.getDimensionPixelOffset(R.styleable.CodeScannerView_frameThickness, Math.round(DEFAULT_FRAME_THICKNESS_DP * density))); setFrameCornersSize( a.getDimensionPixelOffset(R.styleable.CodeScannerView_frameCornersSize, Math.round(DEFAULT_FRAME_CORNER_SIZE_DP * density))); setFrameCornersRadius( a.getDimensionPixelOffset(R.styleable.CodeScannerView_frameCornersRadius, Math.round(DEFAULT_FRAME_CORNERS_RADIUS_DP * density))); setFrameAspectRatio(a.getFloat(R.styleable.CodeScannerView_frameAspectRatioWidth, DEFAULT_FRAME_ASPECT_RATIO_WIDTH), a.getFloat(R.styleable.CodeScannerView_frameAspectRatioHeight, DEFAULT_FRAME_ASPECT_RATIO_HEIGHT)); setFrameSize(a.getFloat(R.styleable.CodeScannerView_frameSize, DEFAULT_FRAME_SIZE)); setAutoFocusButtonVisible( a.getBoolean(R.styleable.CodeScannerView_autoFocusButtonVisible, DEFAULT_AUTO_FOCUS_BUTTON_VISIBLE)); setFlashButtonVisible(a.getBoolean(R.styleable.CodeScannerView_flashButtonVisible, DEFAULT_FLASH_BUTTON_VISIBLE)); setAutoFocusButtonColor(a.getColor(R.styleable.CodeScannerView_autoFocusButtonColor, DEFAULT_AUTO_FOCUS_BUTTON_COLOR)); setFlashButtonColor(a.getColor(R.styleable.CodeScannerView_flashButtonColor, DEFAULT_FLASH_BUTTON_COLOR)); } finally { if (a != null) { a.recycle(); } } } addView(mPreviewView); addView(mViewFinderView); addView(mAutoFocusButton); addView(mFlashButton); }
Example 9
Source File: VideoActivity.java From Exoplayer_VLC with Apache License 2.0 | 4 votes |
private void changeSurfaceLayout() { int sw; int sh; // get screen size sw = getWindow().getDecorView().getWidth(); sh = getWindow().getDecorView().getHeight(); if (libvlc != null && !libvlc.useCompatSurface()) libvlc.setWindowSize(sw, sh); double dw = sw, dh = sh; boolean isPortrait; isPortrait = false; if (sw > sh && isPortrait || sw < sh && !isPortrait) { dw = sh; dh = sw; } // sanity check if (dw * dh == 0 || mVideoWidth * mVideoHeight == 0) { Log.e(TAG, "Invalid surface size"); return; } // 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_HORIZONTAL: dh = dw / ar; break; case SURFACE_FIT_VERTICAL: dw = dh * ar; 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; } SurfaceView surface; FrameLayout surfaceFrame; surface = mSurfaceView; // surfaceFrame = mSurfaceFrame; // set display size LayoutParams lp = surface.getLayoutParams(); lp.width = (int) Math.ceil(dw * mVideoWidth / mVideoVisibleWidth); lp.height = (int) Math.ceil(dh * mVideoHeight / mVideoVisibleHeight); surface.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(); }
Example 10
Source File: VitamioMedia.java From Vitamio-Cordova-Plugin with MIT License | 4 votes |
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) return; requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); extras = getIntent().getExtras(); // handle extras if (extras == null) { wrapItUp(RESULT_CANCELED, "Error: No options provided"); } else { if (extras.containsKey("isStreaming")) { isStreaming = extras.getBoolean("isStreaming"); } if (extras.containsKey("shouldAutoClose")) { mShouldAutoClose = extras.getBoolean("shouldAutoClose"); } mMediaType = extras.getString("type"); if (mMediaType == null) mMediaType = MEDIA_TYPE_VIDEO; mMediaPlayer = new MediaPlayer(this); mMediaController = new MediaController(this, !isStreaming); mMediaController.setMediaPlayer(this); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); setVolumeControlStream(AudioManager.STREAM_MUSIC); RelativeLayout relLayout = new RelativeLayout(this); if (extras.containsKey("bgColor")) { try { bgColor = Color.parseColor(extras.getString("bgColor")); } catch (Exception e) { Log.v(TAG, "Error parsing color"); Log.e(TAG, e.toString()); bgColor = DEFAULT_BG_COLOR; } } relLayout.setBackgroundColor(bgColor); RelativeLayout.LayoutParams relLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); relLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); mMediaView = new SurfaceView(this); mMediaView.setLayoutParams(relLayoutParam); relLayout.addView(mMediaView); mProgressBar = new ProgressBar(this); mProgressBar.setIndeterminate(true); mProgressBar.setVisibility(View.VISIBLE); RelativeLayout.LayoutParams pblp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); pblp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); mProgressBar.setLayoutParams(pblp); relLayout.addView(mProgressBar); mProgressBar.bringToFront(); mMediaController.setAnchorView(relLayout); mMediaController.setEnabled(true); if (mMediaType.equalsIgnoreCase(MEDIA_TYPE_AUDIO)) { mMediaView.setBackgroundColor(bgColor); if (extras.containsKey("bgImage")) { if (extras.containsKey("bgImageScaleType")) { String scaleType = extras.getString("bgImageScaleType"); if (scaleType.equalsIgnoreCase("fit")) { bgImageScaleType = ImageView.ScaleType.FIT_CENTER; } else if (scaleType.equalsIgnoreCase("stretch")) { bgImageScaleType = ImageView.ScaleType.FIT_XY; } else { bgImageScaleType = ImageView.ScaleType.CENTER; } } bgImage = new ImageView(this); new ImageLoadTask(extras.getString("bgImage"), this).execute(null, null); RelativeLayout.LayoutParams bgImageLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); bgImageLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT); bgImage.setLayoutParams(bgImageLayoutParam); bgImage.setScaleType(bgImageScaleType); relLayout.addView(bgImage); } } setContentView(relLayout, relLayoutParam); holder = mMediaView.getHolder(); holder.addCallback(this); holder.setFormat(PixelFormat.RGBA_8888); } }
Example 11
Source File: CameraUtilsV1.java From CamView with Apache License 2.0 | 4 votes |
static void setupSurfaceAndCameraForPreview(int cameraId, Camera camera, SurfaceView surfaceView) { ImageParameters mImageParameters = new ImageParameters(); Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); // Clockwise rotation needed to align the window display to the natural position int rotation = ((WindowManager) surfaceView.getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: { degrees = 0; break; } case Surface.ROTATION_90: { degrees = 90; break; } case Surface.ROTATION_180: { degrees = 180; break; } case Surface.ROTATION_270: { degrees = 270; break; } } int displayOrientation; // CameraInfo.Orientation is the angle relative to the natural position of the device // in clockwise rotation (angle that is rotated clockwise from the natural position) if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { // Orientation is angle of rotation when facing the camera for // the camera image to match the natural orientation of the device displayOrientation = (cameraInfo.orientation + degrees) % 360; displayOrientation = (360 - displayOrientation) % 360; } else { displayOrientation = (cameraInfo.orientation - degrees + 360) % 360; } mImageParameters.mDisplayOrientation = displayOrientation; mImageParameters.mLayoutOrientation = degrees; camera.setDisplayOrientation(mImageParameters.mDisplayOrientation); Camera.Parameters parameters = camera.getParameters(); Camera.Size sz = getOptimalPreviewSize(parameters.getSupportedPreviewSizes(), surfaceView.getWidth(), surfaceView.getHeight()); parameters.setPreviewSize(sz.width, sz.height); //landscape float ratio = 0; if (surfaceView.getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { ratio = (float) sz.width / sz.height; } else { ratio = (float) sz.height / sz.width; } int new_width = 0, new_height = 0; if (surfaceView.getWidth() / surfaceView.getHeight() < ratio) { new_width = Math.round(surfaceView.getHeight() * ratio); new_height = surfaceView.getHeight(); } else { new_width = surfaceView.getWidth(); new_height = Math.round(surfaceView.getWidth() / ratio); } FrameLayout.LayoutParams prms = new FrameLayout.LayoutParams(new_width, new_height); prms.gravity = Gravity.CENTER; surfaceView.setLayoutParams(prms); // Set continuous picture focus, if it's supported if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } // Lock in the changes camera.setParameters(parameters); }