Example usage for android.view SurfaceView getHolder

List of usage examples for android.view SurfaceView getHolder

Introduction

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

Prototype

public SurfaceHolder getHolder() 

Source Link

Document

Return the SurfaceHolder providing access and control over this SurfaceView's underlying surface.

Usage

From source file:ch.jeda.platform.android.CanvasFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final SurfaceView result = new SurfaceView(this.getActivity());
    result.setFocusable(true);/*from   www .  ja va 2 s.c om*/
    result.setFocusableInTouchMode(true);
    result.setOnKeyListener(this);
    result.setOnTouchListener(this);
    this.surfaceHolder = result.getHolder();
    this.surfaceHolder.addCallback(this);
    return result;
}

From source file:piuk.blockchain.android.ui.zxing.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;/*from  w w  w .j a v  a  2s .  c  om*/
    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }

    inactivityTimer.onResume();

    Intent intent = getIntent();

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();

        if (Intents.Scan.ACTION.equals(action)) {

            // Scan the formats the intent requested, and return the result to the calling activity.
            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);
                }
            }
        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }
}

From source file:se.droidgiro.scanner.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();
    resetStatusView();//from   ww  w . ja  v a2  s  . c  o m

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    playBeep = prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP, true);
    if (playBeep) {
        // See if sound settings overrides this
        AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
        if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
            playBeep = false;
        }
    }
    vibrate = prefs.getBoolean(PreferencesActivity.KEY_VIBRATE, false);
    initBeepSound();
}

From source file:tw.jwzhuang.ipcamviewer.devices.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;//  w  w  w .  j  a v a  2 s. c  om
    lastResult = null;

    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    inactivityTimer.onResume();

    Intent intent = getIntent();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    copyToClipboard = prefs.getBoolean(Contant.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)) {

            // Scan the formats the intent requested, and return the result
            // to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(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);
                }
            }

        } else if (dataString != null && dataString.contains(PRODUCT_SEARCH_URL_PREFIX)
                && dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {

            // Scan only products and send the result to mobile Product
            // Search.
            source = IntentSource.PRODUCT_SEARCH_LINK;
            sourceUrl = dataString;
            decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

        } else if (isZXingURL(dataString)) {

            // Scan formats requested in query string (all formats if none
            // specified).
            // If a return URL is specified, send the results there.
            // Otherwise, handle it ourselves.
            source = IntentSource.ZXING_LINK;
            sourceUrl = dataString;
            Uri inputUri = Uri.parse(sourceUrl);
            inputUri.getQueryParameter(RETURN_URL_PARAM);
            decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);

        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }
}

From source file:org.madmatrix.zxing.android.CaptureActivity.java

@Override
protected void onPause() {
    if (handler != null) {
        handler.quitSynchronously();/*from  w w  w  . java  2  s. c om*/
        handler = null;
    }

    // ?
    inactivityTimer.onPause();

    // ??
    cameraManager.closeDriver();
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
    super.onPause();
}

From source file:org.madmatrix.zxing.android.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    /**/*  w  w  w.  j  a v a 2s . co  m*/
     * ?????????
     * ?onCreateonCreate????bug
     */
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);
    resultView = findViewById(R.id.result_view);
    statusView = (TextView) findViewById(R.id.status_view);

    handler = null;
    lastResult = null;

    // ???????
    resetStatusView();

    // ???SurfaceView???
    // ?SurfaceView??:http://blog.csdn.net/luoshengyang/article/details/8661317
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        // SurfaceViewsurfaceCreatedsurfaceCreatedinitCamera()
        surfaceHolder.addCallback(this);
    }

    // ?
    inactivityTimer.onResume();

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;
}

From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);//from   w  ww  .  ja  v a2 s  . co  m

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.setOnTouchListener(this);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.setFormat(PixelFormat.RGB_565);
    surfaceHolder.addCallback(this);

    messageView = (TextView) findViewById(R.id.message_label);
    messageView.bringToFront();

    transparentView = findViewById(R.id.transparent_view);
    numPlayersSelector = (Spinner) findViewById(R.id.num_players);

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.playerNumber,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    numPlayersSelector.setAdapter(adapter);

    button = (Button) findViewById(R.id.continue_button);
    button.setOnClickListener(this);

    statusTopleft = (TextView) findViewById(R.id.status_topleft);
    statusTopright = (TextView) findViewById(R.id.status_topright);
    statusBotleft = (TextView) findViewById(R.id.status_botleft);
    statusBotright = (TextView) findViewById(R.id.status_botright);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            onClick(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (activityState == ActivityStateEnum.GAMERUNNING)
                showPauseScreen();
        }
    });

    statusTopright.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            statusTopright.setTextColor(0xffCCCCFF);
            secretHandshake += 1;
        }
    });

    statusBotright.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (secretHandshake > 4) {
                statusBotright.setTextColor(0xffCCCCFF);
                final NetworkIP n = new NetworkIP((int) System.currentTimeMillis());
                n.startServer();
                n.clientConnect("127.0.0.1", 1234);
            }
        }
    });

    scores = new Scores(getSharedPreferences("scores", Context.MODE_PRIVATE));
    scores.loadScores();

    if (savedInstanceState == null) {
        showIntroScreen();
    }
}

From source file:com.google.zxing.client.android.CaptureActivity.java

@Override
protected void onPause() {
    if (handler != null) {
        handler.quitSynchronously();/*from  w ww.  j av a2s  .  c o m*/
        handler = null;
    }
    inactivityTimer.onPause();
    ambientLightManager.stop();
    cameraManager.closeDriver();
    // historyManager = null; // Keep for onActivityResult
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) findViewById(EUExUtil.getResIdID("preview_view"));
        if (surfaceView != null) {
            SurfaceHolder surfaceHolder = surfaceView.getHolder();
            surfaceHolder.removeCallback(this);
        }
    }
    super.onPause();
}

From source file:com.google.zxing.client.android.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();
    Log.i("djf", "onResume");
    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = CameraManager.getInstance(getApplication());

    handler = null;/*ww  w  . j  a  v  a  2  s . c o  m*/

    // resetStatusView();

    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    Intent intent = getIntent();

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {
        String action = intent.getAction();
        if (Intents.Scan.ACTION.equals(action)) {
            // Scan the formats the intent requested, and return the result
            // to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
        }
        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
    }

    SurfaceView surfaceView = (SurfaceView) findViewById(EUExUtil.getResIdID("plugin_uexscanner_preview_view"));
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
    }
}

From source file:br.com.skylane.voicer.rtp.RtpMediaDecoder.java

public RtpMediaDecoder(SurfaceView surfaceView) {

    log.info("RtpMediaDecoder started with params (" + DEBUGGING + "," + bufferType + "," + useNio + ","
            + receiveBufferSize + ")");

    this.surfaceView = surfaceView;
    surfaceView.getHolder().addCallback(this);
    //this.baos = new ByteArrayOutputStream();
}