Example usage for android.view SurfaceView getLayoutParams

List of usage examples for android.view SurfaceView getLayoutParams

Introduction

In this page you can find the example usage for android.view SurfaceView getLayoutParams.

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:com.jwork.spycamera.MainFragment.java

public void setVisibleForWidget() {
    log.v(this, "setVisibleForWidget()");
    ((RelativeLayout) view.findViewById(R.id.wholeLayout)).setVisibility(View.VISIBLE);
    ((LinearLayout) view.findViewById(R.id.linearLayoutLeft)).setVisibility(View.INVISIBLE);
    ((LinearLayout) view.findViewById(R.id.linearLayoutRight)).setVisibility(View.INVISIBLE);
    ((LinearLayout) view.findViewById(R.id.linearLayoutCenterButton)).setVisibility(View.INVISIBLE);
    ((Button) view.findViewById(R.id.btnDecreaseSize)).setVisibility(View.INVISIBLE);
    ((Button) view.findViewById(R.id.btnIncreaseSize)).setVisibility(View.INVISIBLE);
    SurfaceView svPreview = ((SurfaceView) view.findViewById(R.id.svPreview));
    ViewGroup.LayoutParams params = svPreview.getLayoutParams();
    params.height = 1;//ww  w .j  av  a 2 s  .c  o  m
    params.width = 1;
    svPreview.setLayoutParams(params);
}

From source file:paulscode.android.mupen64plusae.game.GameFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mAppData = new AppData(getActivity());

    mMogaController = Controller.getInstance(getActivity());

    // Initialize the objects and data files interfacing to the emulator core
    final FragmentManager fm = getActivity().getSupportFragmentManager();
    mCoreFragment = (CoreFragment) fm.findFragmentByTag(STATE_CORE_FRAGMENT);

    if (mCoreFragment == null) {
        mCoreFragment = new CoreFragment();
        fm.beginTransaction().add(mCoreFragment, STATE_CORE_FRAGMENT).commit();
    }/*from w ww . j  a  v a2s  . co m*/

    mCoreFragment.setCoreEventListener(this);

    // Get the args data
    mRomPath = getArguments().getString(ActivityHelper.Keys.ROM_PATH);
    mRomMd5 = getArguments().getString(ActivityHelper.Keys.ROM_MD5);
    mRomCrc = getArguments().getString(ActivityHelper.Keys.ROM_CRC);
    mRomHeaderName = getArguments().getString(ActivityHelper.Keys.ROM_HEADER_NAME);
    mRomCountryCode = getArguments().getByte(ActivityHelper.Keys.ROM_COUNTRY_CODE);
    mRomArtPath = getArguments().getString(ActivityHelper.Keys.ROM_ART_PATH);
    mRomGoodName = getArguments().getString(ActivityHelper.Keys.ROM_GOOD_NAME);
    mRomLegacySave = getArguments().getString(ActivityHelper.Keys.ROM_LEGACY_SAVE);
    mDoRestart = getArguments().getBoolean(ActivityHelper.Keys.DO_RESTART, false);
    if (TextUtils.isEmpty(mRomPath) || TextUtils.isEmpty(mRomMd5))
        throw new Error("ROM path and MD5 must be passed via the extras bundle when starting GameFragment");

    // Initialize MOGA controller API
    // TODO: Remove hack after MOGA SDK is fixed
    // mMogaController.init();
    MogaHack.init(mMogaController, getActivity());

    // Get app data and user preferences
    mGlobalPrefs = new GlobalPrefs(getActivity(), mAppData);

    //Allow volume keys to control media volume if they are not mapped

    if (!mGlobalPrefs.volKeysMappable && mGlobalPrefs.audioPlugin.enabled) {
        getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }

    mGamePrefs = new GamePrefs(getActivity(), mRomMd5, mRomCrc, mRomHeaderName, mRomGoodName,
            CountryCode.getCountryCode(mRomCountryCode).toString(), mAppData, mGlobalPrefs, mRomLegacySave);

    mGameDataManager = new GameDataManager(mGlobalPrefs, mGamePrefs, mGlobalPrefs.maxAutoSaves);
    mGameDataManager.makeDirs();
    mGameDataManager.moveFromLegacy();

    final Window window = getActivity().getWindow();

    // Enable full-screen mode
    window.setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
    window.setFlags(LayoutParams.FLAG_LAYOUT_IN_SCREEN, LayoutParams.FLAG_LAYOUT_IN_SCREEN);

    // Keep screen from going to sleep
    window.setFlags(LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON);

    mFirstStart = true;

    // Lay out content and get the views
    SurfaceView surfaceView = (SurfaceView) getView().findViewById(R.id.gameSurface);

    mOverlay = (GameOverlay) getView().findViewById(R.id.gameOverlay);
    mDrawerLayout = (GameDrawerLayout) getView().findViewById(R.id.drawerLayout);
    mGameSidebar = (GameSidebar) getView().findViewById(R.id.gameSidebar);

    // Don't darken the game screen when the drawer is open
    mDrawerLayout.setScrimColor(0x0);
    mDrawerLayout.setSwipGestureEnabled(mGlobalPrefs.inGameMenuIsSwipGesture);
    mDrawerLayout.setBackgroundColor(0xFF000000);

    if (!TextUtils.isEmpty(mRomArtPath) && new File(mRomArtPath).exists())
        mGameSidebar.setImage(new BitmapDrawable(this.getResources(), mRomArtPath));

    mGameSidebar.setTitle(mRomGoodName);

    // Handle events from the side bar
    mGameSidebar.setActionHandler(this, R.menu.game_drawer);

    // Listen to game surface events (created, changed, destroyed)
    surfaceView.getHolder().addCallback(this);

    // Update the SurfaceView size
    surfaceView.getHolder().setFixedSize(mGamePrefs.videoRenderWidth, mGamePrefs.videoRenderHeight);
    final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) surfaceView.getLayoutParams();
    params.width = Math.round(mGamePrefs.videoSurfaceWidth * (mGamePrefs.videoSurfaceZoom / 100.f));
    params.height = Math.round(mGamePrefs.videoSurfaceHeight * (mGamePrefs.videoSurfaceZoom / 100.f));
    params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    surfaceView.setLayoutParams(params);

    // Initialize the screen elements
    if (mGamePrefs.isTouchscreenEnabled || mGlobalPrefs.isFpsEnabled) {
        // The touch map and overlay are needed to display frame rate and/or controls
        mTouchscreenMap = new VisibleTouchMap(this.getResources());
        mTouchscreenMap.load(mGamePrefs.touchscreenSkin, mGamePrefs.touchscreenProfile,
                mGlobalPrefs.isTouchscreenAnimated, mGlobalPrefs.isFpsEnabled, mGlobalPrefs.fpsXPosition,
                mGlobalPrefs.fpsYPosition, mGlobalPrefs.touchscreenScale, mGlobalPrefs.touchscreenTransparency);
        mOverlay.initialize(mCoreFragment, mTouchscreenMap, !mGamePrefs.isTouchscreenHidden,
                mGlobalPrefs.isFpsEnabled, mGamePrefs.isAnalogHiddenWhenSensor,
                mGlobalPrefs.isTouchscreenAnimated);
    }

    // Initialize user interface devices
    initControllers(mOverlay);

    // Override the peripheral controllers' key provider, to add some extra
    // functionality
    mOverlay.setOnKeyListener(this);
    mOverlay.requestFocus();

    if (savedInstanceState == null) {
        // Show the drawer at the start and have it hide itself
        // automatically
        mDrawerLayout.openDrawer(GravityCompat.START);
        mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mDrawerLayout.closeDrawer(GravityCompat.START);
            }
        }, 1000);
    }

    if (mDrawerOpenState) {
        Log.e("CoreFragment", "Opening drawer");
        mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mCoreFragment.pauseEmulator();
                mDrawerLayout.openDrawer(GravityCompat.START);
            }
        }, 1000);

    }

    mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerClosed(View arg0) {
            if (!mShuttingDown) {
                mCoreFragment.resumeEmulator();
                mDrawerOpenState = false;
            }

        }

        @Override
        public void onDrawerOpened(View arg0) {
            mCoreFragment.pauseEmulator();
            ReloadAllMenus();
        }

        @Override
        public void onDrawerSlide(View arg0, float arg1) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }

    });

    // Check periodically for touch input to determine if we should
    // hide the controls
    mHandler = new Handler();
    Calendar calendar = Calendar.getInstance();
    mLastTouchTime = calendar.get(Calendar.SECOND);

    if (mGlobalPrefs.touchscreenAutoHideEnabled)
        mHandler.postDelayed(mLastTouchChecker, 500);

    //Callback for onWindowFocusChanged
    final ViewTreeObserver viewTreeObserver = getView().getViewTreeObserver();
    viewTreeObserver.addOnWindowFocusChangeListener(this);

    //Callback for onGenericMotion
    getView().setOnGenericMotionListener(this);
}