Search in sources :

Example 91 with SurfaceHolder

use of android.view.SurfaceHolder in project Osmand by osmandapp.

the class AudioVideoNotesPlugin method takePhotoWithCamera.

private void takePhotoWithCamera(final double lat, final double lon, final MapActivity mapActivity) {
    try {
        lastTakingPhoto = getBaseFileName(lat, lon, app, IMG_EXTENSION);
        final Camera.Size mPreviewSize;
        Parameters parameters = cam.getParameters();
        List<Camera.Size> psps = parameters.getSupportedPictureSizes();
        int camPicSizeIndex = AV_CAMERA_PICTURE_SIZE.get();
        // camera picture size
        log.debug("takePhotoWithCamera() index=" + camPicSizeIndex);
        if (camPicSizeIndex == AV_PHOTO_SIZE_DEFAULT) {
            camPicSizeIndex = cameraPictureSizeDefault;
            log.debug("takePhotoWithCamera() Default value of picture size. Set index to cameraPictureSizeDefault. Now index=" + camPicSizeIndex);
        }
        final Camera.Size selectedCamPicSize = psps.get(camPicSizeIndex);
        if (mSupportedPreviewSizes != null) {
            int width = selectedCamPicSize.width;
            int height = selectedCamPicSize.height;
            mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
        } else {
            mPreviewSize = null;
        }
        final SurfaceView view;
        if (mPreviewSize != null) {
            view = recordingMenu.prepareSurfaceView(mPreviewSize.width, mPreviewSize.height);
        } else {
            view = recordingMenu.prepareSurfaceView();
        }
        view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        view.getHolder().addCallback(new Callback() {

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
            }

            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                try {
                    // load sound befor shot
                    if (AV_PHOTO_PLAY_SOUND.get()) {
                        if (sp == null)
                            sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
                        if (shotId == 0) {
                            try {
                                AssetFileDescriptor assetFileDescriptor = app.getAssets().openFd("sounds/camera_click.ogg");
                                shotId = sp.load(assetFileDescriptor, 1);
                                assetFileDescriptor.close();
                            } catch (Exception e) {
                                log.error("cannot get shotId for sounds/camera_click.ogg");
                            }
                        }
                    }
                    Parameters parameters = cam.getParameters();
                    parameters.setPictureSize(selectedCamPicSize.width, selectedCamPicSize.height);
                    log.debug("takePhotoWithCamera() set Picture size: width=" + selectedCamPicSize.width + " height=" + selectedCamPicSize.height);
                    // camera focus type
                    autofocus = true;
                    parameters.removeGpsData();
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                        parameters.setGpsLatitude(lat);
                        parameters.setGpsLongitude(lon);
                    }
                    switch(AV_CAMERA_FOCUS_TYPE.get()) {
                        case AV_CAMERA_FOCUS_HIPERFOCAL:
                            parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
                            autofocus = false;
                            log.info("Osmand:AudioNotes set camera FOCUS_MODE_FIXED");
                            break;
                        case AV_CAMERA_FOCUS_EDOF:
                            parameters.setFocusMode(Parameters.FOCUS_MODE_EDOF);
                            autofocus = false;
                            log.info("Osmand:AudioNotes set camera FOCUS_MODE_EDOF");
                            break;
                        case AV_CAMERA_FOCUS_INFINITY:
                            parameters.setFocusMode(Parameters.FOCUS_MODE_INFINITY);
                            autofocus = false;
                            log.info("Osmand:AudioNotes set camera FOCUS_MODE_INFINITY");
                            break;
                        case AV_CAMERA_FOCUS_MACRO:
                            parameters.setFocusMode(Parameters.FOCUS_MODE_MACRO);
                            log.info("Osmand:AudioNotes set camera FOCUS_MODE_MACRO");
                            break;
                        case AV_CAMERA_FOCUS_CONTINUOUS:
                            parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                            log.info("Osmand:AudioNotes set camera FOCUS_MODE_CONTINUOUS_PICTURE");
                            break;
                        default:
                            parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
                            log.info("Osmand:AudioNotes set camera FOCUS_MODE_AUTO");
                            break;
                    }
                    if (parameters.getSupportedWhiteBalance() != null && parameters.getSupportedWhiteBalance().contains(Parameters.WHITE_BALANCE_AUTO)) {
                        parameters.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);
                    }
                    if (parameters.getSupportedFlashModes() != null && parameters.getSupportedFlashModes().contains(Parameters.FLASH_MODE_AUTO)) {
                    // parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
                    }
                    int cameraOrientation = getCamOrientation(mapActivity, Camera.CameraInfo.CAMERA_FACING_BACK);
                    cam.setDisplayOrientation(cameraOrientation);
                    parameters.set("rotation", cameraOrientation);
                    if (mPreviewSize != null) {
                        parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
                    }
                    cam.setParameters(parameters);
                    cam.setPreviewDisplay(holder);
                    cam.startPreview();
                    internalShoot();
                } catch (Exception e) {
                    logErr(e);
                    closeRecordingMenu();
                    closeCamera();
                    finishRecording();
                    e.printStackTrace();
                }
            }

            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            }
        });
        recordingMenu.show();
    } catch (RuntimeException e) {
        logErr(e);
        closeCamera();
    }
}
Also used : Parameters(android.hardware.Camera.Parameters) AssetFileDescriptor(android.content.res.AssetFileDescriptor) SoundPool(android.media.SoundPool) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) IOException(java.io.IOException) SurfaceHolder(android.view.SurfaceHolder) PictureCallback(android.hardware.Camera.PictureCallback) Callback(android.view.SurfaceHolder.Callback) Camera(android.hardware.Camera) SurfaceView(android.view.SurfaceView)

Example 92 with SurfaceHolder

use of android.view.SurfaceHolder in project ring-client-android by savoirfairelinux.

the class HardwareServiceImpl method addVideoSurface.

@Override
public void addVideoSurface(String id, Object holder) {
    if (!(holder instanceof SurfaceHolder)) {
        return;
    }
    Log.w(TAG, "addVideoSurface " + id + holder.hashCode());
    Shm shm = videoInputs.get(id);
    WeakReference<SurfaceHolder> surfaceHolder = new WeakReference<>((SurfaceHolder) holder);
    videoSurfaces.put(id, surfaceHolder);
    if (shm != null && shm.window == 0) {
        shm.window = startVideo(shm.id, surfaceHolder.get().getSurface(), shm.w, shm.h);
    }
    if (shm == null || shm.window == 0) {
        Log.i(TAG, "DRingService.addVideoSurface() no window !");
        ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
        event.addEventInput(ServiceEvent.EventInput.VIDEO_START, true);
        setChanged();
        notifyObservers(event);
        return;
    }
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_CALL, shm.id);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_STARTED, true);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_WIDTH, shm.w);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_HEIGHT, shm.h);
    setChanged();
    notifyObservers(event);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) ServiceEvent(cx.ring.model.ServiceEvent) WeakReference(java.lang.ref.WeakReference)

Example 93 with SurfaceHolder

use of android.view.SurfaceHolder in project ring-client-android by savoirfairelinux.

the class TVCallFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
    mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "cx.ring.onIncomingCall");
    mScreenWakeLock.setReferenceCounted(false);
    if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) {
        mScreenWakeLock.acquire();
    }
    mVideoSurface.getHolder().setFormat(PixelFormat.RGBA_8888);
    mVideoSurface.getHolder().addCallback(new SurfaceHolder.Callback() {

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            presenter.videoSurfaceCreated(holder);
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            presenter.videoSurfaceDestroyed();
        }
    });
    mVideoPreview.getHolder().setFormat(PixelFormat.RGBA_8888);
    mVideoPreview.getHolder().addCallback(new SurfaceHolder.Callback() {

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            presenter.previewVideoSurfaceCreated(holder);
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            presenter.previewVideoSurfaceDestroyed();
        }
    });
    mVideoPreview.setZOrderMediaOverlay(true);
    shapeRipple.setRippleShape(new Circle());
    handler = new Handler();
    runnable = () -> presenter.uiVisibilityChanged(false);
}
Also used : PowerManager(android.os.PowerManager) SurfaceHolder(android.view.SurfaceHolder) Circle(com.rodolfonavalon.shaperipplelibrary.model.Circle) Handler(android.os.Handler)

Example 94 with SurfaceHolder

use of android.view.SurfaceHolder in project Zom-Android by zom.

the class CameraView method start.

void start(Camera newCamera, PreviewConsumer previewConsumer, int rotationDegrees, boolean macro) {
    camera = newCamera;
    this.previewConsumer = previewConsumer;
    setDisplayOrientation(rotationDegrees);
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    // Required on Android < 3.0
    holder.setType(SURFACE_TYPE_PUSH_BUFFERS);
    if (surfaceExists)
        startPreview(holder);
    new Thread() {

        public void run() {
            while (camera != null) {
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                }
                try {
                    camera.autoFocus(CameraView.this);
                } catch (Exception e) {
                    Log.w(ImApp.LOG_TAG, "qr code scanning not working: " + e.toString());
                }
            }
        }
    }.start();
}
Also used : SurfaceHolder(android.view.SurfaceHolder) IOException(java.io.IOException)

Example 95 with SurfaceHolder

use of android.view.SurfaceHolder in project Osmand by osmandapp.

the class OsmandMapTileView method refreshMapInternal.

private void refreshMapInternal(DrawSettings drawSettings) {
    if (view == null) {
        return;
    }
    final float ratioy;
    if (mapRatioY != 0) {
        ratioy = mapRatioY;
    } else if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) {
        ratioy = 0.85f;
    } else if (mapPosition == OsmandSettings.MIDDLE_BOTTOM_CONSTANT) {
        ratioy = 0.70f;
    } else if (mapPosition == OsmandSettings.MIDDLE_TOP_CONSTANT) {
        ratioy = 0.25f;
    } else {
        ratioy = 0.5f;
    }
    final float ratiox;
    if (mapRatioX != 0) {
        ratiox = mapRatioX;
    } else if (mapPosition == OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT) {
        ratiox = 0.7f;
    } else {
        ratiox = mapPositionX == 0 ? 0.5f : 0.75f;
    }
    final int cy = (int) (ratioy * view.getHeight());
    final int cx = (int) (ratiox * view.getWidth());
    if (currentViewport.getPixWidth() != view.getWidth() || currentViewport.getPixHeight() != view.getHeight() || currentViewport.getCenterPixelY() != cy || currentViewport.getCenterPixelX() != cx) {
        currentViewport.setPixelDimensions(view.getWidth(), view.getHeight(), ratiox, ratioy);
        refreshBufferImage(drawSettings);
    }
    if (view instanceof SurfaceView) {
        SurfaceHolder holder = ((SurfaceView) view).getHolder();
        long ms = SystemClock.elapsedRealtime();
        synchronized (holder) {
            Canvas canvas = holder.lockCanvas();
            if (canvas != null) {
                try {
                    // make copy to avoid concurrency
                    RotatedTileBox viewportToDraw = currentViewport.copy();
                    drawOverMap(canvas, viewportToDraw, drawSettings);
                } finally {
                    holder.unlockCanvasAndPost(canvas);
                }
            }
            if (MEASURE_FPS) {
                main.calculateFPS(ms, SystemClock.elapsedRealtime());
            }
        }
    } else {
        view.invalidate();
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) RotatedTileBox(net.osmand.data.RotatedTileBox) Canvas(android.graphics.Canvas) QuadPoint(net.osmand.data.QuadPoint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) SurfaceView(android.view.SurfaceView)

Aggregations

SurfaceHolder (android.view.SurfaceHolder)189 SurfaceView (android.view.SurfaceView)62 LargeTest (android.test.suitebuilder.annotation.LargeTest)50 Parameters (android.hardware.Camera.Parameters)37 IOException (java.io.IOException)29 MediaPlayer (android.media.MediaPlayer)17 Surface (android.view.Surface)16 SurfaceTexture (android.graphics.SurfaceTexture)14 CamcorderProfile (android.media.CamcorderProfile)13 MediaRecorder (android.media.MediaRecorder)13 Camera (android.hardware.Camera)9 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)9 Paint (android.graphics.Paint)8 AudioManager (android.media.AudioManager)8 SharedPreferences (android.content.SharedPreferences)7 MediaVideoItem (android.media.videoeditor.MediaVideoItem)7 CameraManager (com.google.zxing.client.android.camera.CameraManager)7 Intent (android.content.Intent)6 VideoEditor (android.media.videoeditor.VideoEditor)6 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)6