Java Code Examples for android.view.SurfaceView#getLayoutParams()

The following examples show how to use android.view.SurfaceView#getLayoutParams() . 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 vote down vote up
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: RTSPPlayerActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
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 3
Source File: SRTPlayerActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
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 4
Source File: VideoActivity.java    From Exoplayer_VLC with Apache License 2.0 4 votes vote down vote up
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(); 
}