Example usage for android.view SurfaceHolder setFixedSize

List of usage examples for android.view SurfaceHolder setFixedSize

Introduction

In this page you can find the example usage for android.view SurfaceHolder setFixedSize.

Prototype

public void setFixedSize(int width, int height);

Source Link

Document

Make the surface a fixed size.

Usage

From source file:com.intel.xdk.display.Display.java

@JavascriptInterface
public void startAR() {
    arView = CameraPreview.newInstance(activity.getApplicationContext());
    arView.setVisibility(View.INVISIBLE);

    arView.height = 100;/*from   ww w.j a v a 2s  .  c o m*/
    arView.width = 100;

    //no way to get current background color?
    arView.setBackgroundColor(Color.TRANSPARENT);

    SurfaceHolder sfhTrackHolder = arView.getHolder();
    sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT);
    sfhTrackHolder.setKeepScreenOn(true);
    sfhTrackHolder.setFixedSize(100, 100);

    activity.runOnUiThread(new Runnable() {
        public void run() {

            //activity.addContentView(arView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
            //activity.addContentView(arView, new LinearLayout.LayoutParams(400, 500, 0.0F));
            ViewGroup rootView = (ViewGroup) webView.getParent().getParent();
            rootView.addView(arView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.FILL_PARENT));
            rootView.bringChildToFront((View) webView.getParent());

            arView.setVisibility(View.VISIBLE);
            arView.showCamera();
            webView.bringToFront();
            webView.setBackgroundColor(0x00000000);
            LinearLayout ll = (LinearLayout) webView.getParent();
            ll.setBackgroundColor(0x00000000);

            View activityView = activity.getCurrentFocus();
        }
    });
}

From source file:uk.co.armedpineapple.cth.SDLActivity.java

void loadApplication() {

    // Load the libraries
    System.loadLibrary("SDL");
    System.loadLibrary("luajit");
    System.loadLibrary("SDL_mixer");
    System.loadLibrary("ffmpeg");
    System.loadLibrary("appmain");

    try {//from w w  w  .j a  v  a2 s  .  c o  m
        app.configuration.writeToFile();
    } catch (IOException e) {
        e.printStackTrace();
        Log.e(LOG_TAG, "Couldn't write to configuration file");
        BugSenseHandler.sendException(e);
    }

    File f = new File(app.configuration.getSaveGamesPath());

    if (!f.isDirectory()) {
        f.mkdirs();
    }

    // So we can call stuff from static callbacks
    mSingleton = this;

    hideSystemUi();

    mSurface = new SDLSurface(this, app.configuration.getDisplayWidth(), app.configuration.getDisplayHeight());
    mSurface.setZOrderOnTop(false);

    DrawerLayout mainLayout = (DrawerLayout) getLayoutInflater().inflate(R.layout.game, null);
    FrameLayout gameFrame = ((FrameLayout) mainLayout.findViewById(R.id.game_frame));

    gameFrame.addView(mSurface);
    setContentView(mainLayout);

    mHapticLauncher = new Launcher(this);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.main_layout);
    mDrawerList = (ListView) findViewById(R.id.menu_drawer);
    mDrawerList.setAdapter(new NavDrawerAdapter(this,
            uk.co.armedpineapple.cth.MenuItems.getItems(BuildConfig.DEBUG || app.configuration.getDebug())));
    mDrawerList.setOnItemClickListener(new NavDrawerListListener(this));
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mDrawerLayout.setDrawerListener(new DrawerListener() {

        @Override
        public void onDrawerClosed(View arg0) {
            // Restore game speed
            cthGameSpeed(app.configuration.getGameSpeed());
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }

        @Override
        public void onDrawerOpened(View arg0) {
            // Pause the game
            cthGameSpeed(0);
        }

        @Override
        public void onDrawerSlide(View arg0, float arg1) {
            arg0.bringToFront();
            mDrawerLayout.bringChildToFront(arg0);
            mDrawerLayout.requestLayout();

        }

        @Override
        public void onDrawerStateChanged(int arg0) {
            // TODO Auto-generated method stub

        }

    });
    SurfaceHolder holder = mSurface.getHolder();
    holder.setFixedSize(app.configuration.getDisplayWidth(), app.configuration.getDisplayHeight());

    gameFrame.setVisibility(View.VISIBLE);

    hasGameLoaded = true;

}

From source file:butter.droid.base.fragments.BaseVideoPlayerFragment.java

@SuppressWarnings("SuspiciousNameCombination")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void changeSurfaceSize(boolean message) {
    int screenWidth = getActivity().getWindow().getDecorView().getWidth();
    int screenHeight = getActivity().getWindow().getDecorView().getHeight();

    if (mMediaPlayer != null) {
        final IVLCVout vlcVout = mMediaPlayer.getVLCVout();
        vlcVout.setWindowSize(screenWidth, screenHeight);
    }//from  w ww.  j  a v  a  2 s  . c om

    double displayWidth = screenWidth, displayHeight = screenHeight;

    if (screenWidth < screenHeight) {
        displayWidth = screenHeight;
        displayHeight = screenWidth;
    }

    // sanity check
    if (displayWidth * displayHeight <= 1 || mVideoWidth * mVideoHeight <= 1) {
        Timber.e("Invalid surface size");
        onErrorEncountered();
        return;
    }

    // compute the aspect ratio
    double aspectRatio, visibleWidth;
    if (mSarDen == mSarNum) {
        /* No indication about the density, assuming 1:1 */
        visibleWidth = mVideoVisibleWidth;
        aspectRatio = (double) mVideoVisibleWidth / (double) mVideoVisibleHeight;
    } else {
        /* Use the specified aspect ratio */
        visibleWidth = mVideoVisibleWidth * (double) mSarNum / mSarDen;
        aspectRatio = visibleWidth / mVideoVisibleHeight;
    }

    // compute the display aspect ratio
    double displayAspectRatio = displayWidth / displayHeight;

    switch (mCurrentSize) {
    case SURFACE_BEST_FIT:
        if (message)
            showPlayerInfo(getString(R.string.best_fit));
        if (displayAspectRatio < aspectRatio)
            displayHeight = displayWidth / aspectRatio;
        else
            displayWidth = displayHeight * aspectRatio;
        break;
    case SURFACE_FIT_HORIZONTAL:
        displayHeight = displayWidth / aspectRatio;
        if (message)
            showPlayerInfo(getString(R.string.fit_horizontal));
        break;
    case SURFACE_FIT_VERTICAL:
        displayWidth = displayHeight * aspectRatio;
        if (message)
            showPlayerInfo(getString(R.string.fit_vertical));
        break;
    case SURFACE_FILL:
        if (message)
            showPlayerInfo(getString(R.string.fill));
        break;
    case SURFACE_16_9:
        if (message)
            showPlayerInfo("16:9");
        aspectRatio = 16.0 / 9.0;
        if (displayAspectRatio < aspectRatio)
            displayHeight = displayWidth / aspectRatio;
        else
            displayWidth = displayHeight * aspectRatio;
        break;
    case SURFACE_4_3:
        if (message)
            showPlayerInfo("4:3");
        aspectRatio = 4.0 / 3.0;
        if (displayAspectRatio < aspectRatio)
            displayHeight = displayWidth / aspectRatio;
        else
            displayWidth = displayHeight * aspectRatio;
        break;
    case SURFACE_ORIGINAL:
        if (message)
            showPlayerInfo(getString(R.string.original_size));
        displayHeight = mVideoVisibleHeight;
        displayWidth = visibleWidth;
        break;
    }

    // set display size
    int finalWidth = (int) Math.ceil(displayWidth * mVideoWidth / mVideoVisibleWidth);
    int finalHeight = (int) Math.ceil(displayHeight * mVideoHeight / mVideoVisibleHeight);

    SurfaceHolder holder = getVideoSurface().getHolder();
    holder.setFixedSize(finalWidth, finalHeight);

    ViewGroup.LayoutParams lp = getVideoSurface().getLayoutParams();
    lp.width = finalWidth;
    lp.height = finalHeight;
    getVideoSurface().setLayoutParams(lp);
    getVideoSurface().invalidate();
}