List of usage examples for android.view SurfaceView getHolder
public SurfaceHolder getHolder()
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(); }/* w w w. j a v a 2 s. com*/ 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); }
From source file:com.bookkos.bircle.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // cameraManager?????????????(onCreate????????????) cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); // resultView = findViewById(R.id.result_view); handler = null;/* ww w . j a v a 2 s.co m*/ lastResult = null; registFlag = 0; resetStatusView(); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { initCamera(surfaceHolder); } else { surfaceHolder.addCallback(this); } bircleBeepManager.updatePrefs(); ambientLightManager.start(cameraManager); inactivityTimer.onResume(); Intent intent = getIntent(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); decodeHints = DecodeHintManager.parseDecodeHints(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { } } else if (dataString != null && dataString.contains("http://www.google") && dataString.contains("/m/products/scan")) { source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(dataString); decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); decodeHints = DecodeHintManager.parseDecodeHints(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } }