Java Code Examples for android.view.Surface

The following are top voted examples for showing how to use android.view.Surface. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: opencv-documentscanner-android   File: Camera2BasicFragment.java   View source code 6 votes vote down vote up
/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
 
Example 2
Project: MyAnimeViewer   File: CropUtil.java   View source code 6 votes vote down vote up
public static int getOrientationInDegree(Activity activity) {

        int rotation = activity.getWindowManager().getDefaultDisplay()
                .getRotation();
        int degrees = 0;

        switch (rotation) {
            case Surface.ROTATION_0:
                degrees = 0;
                break;
            case Surface.ROTATION_90:
                degrees = 90;
                break;
            case Surface.ROTATION_180:
                degrees = 180;
                break;
            case Surface.ROTATION_270:
                degrees = 270;
                break;
        }

        return degrees;
    }
 
Example 3
Project: RobotIGS   File: Sensors.java   View source code 6 votes vote down vote up
/**
 * Get the natural orientation of the device. For larger phones it is often LANDSCAPE - for smaller, PORTRAIT.
 *
 * @return LANDSCAPE or PORTRAIT, based on the screen information
 */
public ScreenOrientation getDeviceDefaultOrientation() {

    WindowManager windowManager = (WindowManager) Util.getContext().getSystemService(Context.WINDOW_SERVICE);

    Configuration config = Util.getContext().getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
            config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
            config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return ScreenOrientation.LANDSCAPE;
    } else {
        return ScreenOrientation.PORTRAIT;
    }
}
 
Example 4
Project: aos-Video   File: VideoEffectRenderer.java   View source code 6 votes vote down vote up
@Override
protected synchronized void initGLComponents()
{
    if (mEffect != null) {
    mEffect.initGLComponents();
    int videoTexture = mEffect.getVideoTexture();
    mVideoSurfaceTexture = new SurfaceTexture(videoTexture);
    mVideoSurfaceTexture.setOnFrameAvailableListener(this);
    
    int uiTexture = mEffect.getUIOverlayTexture();
    mUISurfaceTexture = new SurfaceTexture(uiTexture);
    mUISurfaceTexture.setDefaultBufferSize(mViewWidth, mViewHeight);
    mUISurface = new Surface(mUISurfaceTexture);
    try {
        Canvas c = mUISurface.lockCanvas(null);
        c.drawColor(0x0);
        mUISurface.unlockCanvasAndPost(c);
    } catch (Exception e) { }
    }
    notifyInit();
}
 
Example 5
Project: ImageClassify   File: CameraConnectionFragment.java   View source code 6 votes vote down vote up
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
  final Activity activity = getActivity();
  if (null == textureView || null == previewSize || null == activity) {
    return;
  }
  final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  final Matrix matrix = new Matrix();
  final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  final float centerX = viewRect.centerX();
  final float centerY = viewRect.centerY();
  if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
    bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
    matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
    final float scale =
        Math.max(
            (float) viewHeight / previewSize.getHeight(),
            (float) viewWidth / previewSize.getWidth());
    matrix.postScale(scale, scale, centerX, centerY);
    matrix.postRotate(90 * (rotation - 2), centerX, centerY);
  } else if (Surface.ROTATION_180 == rotation) {
    matrix.postRotate(180, centerX, centerY);
  }
  textureView.setTransform(matrix);
}
 
Example 6
Project: AAVT   File: Mp4Provider.java   View source code 6 votes vote down vote up
@Override
public Point open(SurfaceTexture surface) {
    try {
        if(!extractMedia()){
            return new Point(0,0);
        }
        mFrameSem=new Semaphore(0);
        mDecodeSem=new Semaphore(1);
        videoProvideEndFlag=false;
        isUserWantToStop=false;
        mAudioEncodeTrack=mStore.addTrack(mExtractor.getTrackFormat(mAudioDecodeTrack));
        MediaFormat format=mExtractor.getTrackFormat(mVideoDecodeTrack);
        mVideoDecoder = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
        mVideoDecoder.configure(format,new Surface(surface),null,0);
        mVideoDecoder.start();
        startDecodeThread();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return mVideoSize;
}
 
Example 7
Project: AndroidBlueprints   File: Utils.java   View source code 6 votes vote down vote up
/**
 * Locks the device window in actual screen mode
 */
public static void lockOrientation(Activity activity) {
    Display display = ((WindowManager) activity.
            getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();
    int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;

    switch (activity.getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_LANDSCAPE:
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90)
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            else
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        case Configuration.ORIENTATION_PORTRAIT:
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270)
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            else
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    }
    //noinspection ResourceType
    activity.setRequestedOrientation(orientation);
}
 
Example 8
Project: SortingHatAndroid   File: CameraConnectionFragment.java   View source code 6 votes vote down vote up
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
  final Activity activity = getActivity();
  if (null == textureView || null == previewSize || null == activity) {
    return;
  }
  final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  final Matrix matrix = new Matrix();
  final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  final float centerX = viewRect.centerX();
  final float centerY = viewRect.centerY();
  if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
    bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
    matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
    final float scale = Math.max((float) viewHeight / previewSize.getHeight(),
        (float) viewWidth / previewSize.getWidth());
    matrix.postScale(scale, scale, centerX, centerY);
    matrix.postRotate(90 * (rotation - 2), centerX, centerY);
  } else if (Surface.ROTATION_180 == rotation) {
    matrix.postRotate(180, centerX, centerY);
  }
  textureView.setTransform(matrix);
}
 
Example 9
Project: VideoRecorder-master   File: Util.java   View source code 6 votes vote down vote up
public static int getRotationAngle(int rotation)
{
	int degrees  = 0;
	switch (rotation) {
	case Surface.ROTATION_0:
		degrees = 0;
		break;

	case Surface.ROTATION_90:
		degrees = 90;
		break;

	case Surface.ROTATION_180:
		degrees = 180;
		break;

	case Surface.ROTATION_270:
		degrees = 270;
		break;
	default:
		break;
	}
	return degrees;
}
 
Example 10
Project: android-api   File: HeadingService.java   View source code 6 votes vote down vote up
private float adjustHeadingForDeviceOrientation(float heading)
{
	switch (m_deviceRotation) {
	    case Surface.ROTATION_0:
	        heading += 0.f;
	        break;
	    case Surface.ROTATION_90:
	    	heading += 90.f;
	        break;
	    case Surface.ROTATION_180:
	    	heading += 180.f;
	        break;
	    default:
	    	heading += 90.f;
	    	break;
	}
					
	heading = (heading + 360.f)%360.f;
	return heading;
}
 
Example 11
Project: VideoApplication   File: MoviePlayer.java   View source code 6 votes vote down vote up
public MoviePlayer(File sourceFile, Surface outputSurface)
        throws IOException {
    // Pop the file open and pull out the video characteristics.
    // TODO: consider leaving the extractor open.  Should be able to just seek back to
    //       the start after each iteration of play.  Need to rearrange the API a bit --
    //       currently play() is taking an all-in-one open+work+release approach.
    try {
        Log.d(TAG, sourceFile.toString());
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        retriever.setDataSource(sourceFile.toString());
        mVideoDuration = Long.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
        Log.d(TAG, "Duration: " + mVideoDuration);
        retriever.release();

        mVideoDecoder = new VideoDecoder(this, sourceFile);
        mVideoDecoder.setOutputSurface(outputSurface);
        mAudioDecoder = new AudioDecoder(this, sourceFile);
        mVideoDecoder.prepare();
        mAudioDecoder.prepare();
    } catch (Exception ex) {
        release();
        throw new IOException(ex.getMessage());
    }
}
 
Example 12
Project: habpanelviewer   File: MotionDetectorCamera2.java   View source code 6 votes vote down vote up
private void configureTransform(TextureView textureView) {
    if (null == textureView || null == mPreviewSize || null == mActivity) {
        return;
    }
    int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, textureView.getWidth(), textureView.getHeight());
    RectF bufferRect = new RectF(0, 0, mPreviewSize.y, mPreviewSize.x);
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) textureView.getHeight() / mPreviewSize.y,
                (float) textureView.getWidth() / mPreviewSize.x);
        matrix.postScale(scale, scale, centerX, centerY);
    }
    matrix.postRotate(-90 * rotation, centerX, centerY);
    textureView.setTransform(matrix);
}
 
Example 13
Project: smart-lens   File: Camera2Api.java   View source code 6 votes vote down vote up
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    if (mPreviewSize == null) return;

    final int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mAutoFitTextureView.setTransform(matrix);
}
 
Example 14
Project: Android-opencv-native-samples   File: ImageControllers.java   View source code 6 votes vote down vote up
private int getDisplayRotation(Context context) {
    WindowManager windowManager = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    int rotation = windowManager.getDefaultDisplay().getRotation();
    switch (rotation) {
        case Surface.ROTATION_0:
            return 0;
        case Surface.ROTATION_90:
            return 90;
        case Surface.ROTATION_180:
            return 180;
        case Surface.ROTATION_270:
            return 270;
    }
    return 0;
}
 
Example 15
Project: AndroidRTC   File: Camera1Session.java   View source code 6 votes vote down vote up
private int getDeviceOrientation() {
  int orientation = 0;

  WindowManager wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
  switch (wm.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
      orientation = 90;
      break;
    case Surface.ROTATION_180:
      orientation = 180;
      break;
    case Surface.ROTATION_270:
      orientation = 270;
      break;
    case Surface.ROTATION_0:
    default:
      orientation = 0;
      break;
  }
  return orientation;
}
 
Example 16
Project: Ocr-android   File: CameraPreview.java   View source code 6 votes vote down vote up
/**
 * 在确定相机预览大小后应调用此方法
 *
 * @param viewWidth  宽
 * @param viewHeight 高
 */
private void configureTransform(int viewWidth, int viewHeight) {
    if (null == mPreviewSize) {
        return;
    }
    int rotation = getDisplayRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    this.setTransform(matrix);
}
 
Example 17
Project: CommonsLab   File: Camera2VideoFragment.java   View source code 6 votes vote down vote up
/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should not to be called until the camera preview size is determined in
 * openCamera, or until the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
 
Example 18
Project: Paper-Melody   File: PlayActivity.java   View source code 6 votes vote down vote up
/**
 * 当手机屏幕的朝向改变时,要对获取到的视频流进行方向上的调整
 *
 * @param viewWidth  TextureView的宽度
 * @param viewHeight TextureView的高度
 */
private void configureTransform(int viewWidth, int viewHeight) {

    if (viewPlay == null || previewSize == null) {
        return;
    }
    int rotation = getWindowManager().getDefaultDisplay().getRotation();

    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    viewPlay.setTransform(matrix);
}
 
Example 19
Project: xbot_head   File: CommentaryFragment.java   View source code 6 votes vote down vote up
private void startPreview() {
    try {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        StreamConfigurationMap configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

        Size previewSize = Util.getPreferredPreviewSize(
                configMap.getOutputSizes(ImageFormat.JPEG),textureView.getWidth(), textureView.getHeight());

        surfaceTexture.setDefaultBufferSize(previewSize.getWidth(),previewSize.getHeight());
        Surface surface = new Surface(surfaceTexture);
        captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        captureBuilder.addTarget(surface);

        cameraDevice.createCaptureSession(Arrays.asList(surface),captureSessionCallback,backgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 20
Project: Fatigue-Detection   File: EGLBase.java   View source code 5 votes vote down vote up
EglSurface(final EGLBase egl, final Object surface) {
	if (DEBUG) Log.v(TAG, "EglSurface:");
	if (!(surface instanceof SurfaceView)
		&& !(surface instanceof Surface)
		&& !(surface instanceof SurfaceHolder)
		&& !(surface instanceof SurfaceTexture))
		throw new IllegalArgumentException("unsupported surface");
	mEgl = egl;
	mEglSurface = mEgl.createWindowSurface(surface);
       mWidth = mEgl.querySurface(mEglSurface, EGL14.EGL_WIDTH);
       mHeight = mEgl.querySurface(mEglSurface, EGL14.EGL_HEIGHT);
       if (DEBUG) Log.v(TAG, String.format("EglSurface:size(%d,%d)", mWidth, mHeight));
}
 
Example 21
Project: InsideCodec   File: FrameProducer.java   View source code 5 votes vote down vote up
public FrameProducer(final EglBase eglBase, final File videoFile, final int fps,
        final Callback callback) {
    mVideoFile = videoFile;
    mFps = fps;
    mCallback = callback;
    mBufferInfo = new MediaCodec.BufferInfo();

    mSurfaceTextureHelper = SurfaceTextureHelper.create("SurfaceTextureHelper",
            eglBase.getEglBaseContext());
    mSurfaceTextureHelper.startListening(this);
    mHubSurface = new Surface(mSurfaceTextureHelper.getSurfaceTexture());
}
 
Example 22
Project: CustomAndroidOneSheeld   File: CameraHeadService.java   View source code 5 votes vote down vote up
public void setCameraDisplayOrientation(int cameraId, android.hardware.Camera camera) {
    android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
    int rotation = windowManager.getDefaultDisplay()
            .getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;  // compensate the mirror
    } else {  // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
}
 
Example 23
Project: TimePicker   File: Utils.java   View source code 5 votes vote down vote up
public static boolean isLandscape(Activity activity) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();

    switch (rotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
            return false;

        case Surface.ROTATION_90:
        case Surface.ROTATION_270:
            return true;
    }
    return true;
}
 
Example 24
Project: GitHub   File: SurfaceRenderView.java   View source code 5 votes vote down vote up
@Nullable
@Override
public Surface openSurface() {
    if (mSurfaceHolder == null)
        return null;
    return mSurfaceHolder.getSurface();
}
 
Example 25
Project: TPlayer   File: MediaPlayer.java   View source code 5 votes vote down vote up
/**
 * Sets the Surface to use for displaying the video portion of the media. This
 * is similar to {@link #setDisplay(SurfaceHolder)}.
 *
 * @param surface the Surface to use for video display
 */
public void setSurface(Surface surface) {
  if (surface == null) {
    releaseDisplay();
  } else {
    mSurfaceHolder = null;
    mSurface = surface;
    _setVideoSurface(mSurface);
    updateSurfaceScreenOn();
  }
}
 
Example 26
Project: live_master   File: SurfaceRenderView.java   View source code 5 votes vote down vote up
@Nullable
@Override
public Surface openSurface() {
    if (mSurfaceHolder == null)
        return null;
    return mSurfaceHolder.getSurface();
}
 
Example 27
Project: PlusGram   File: MediaCodecVideoTrackRenderer.java   View source code 5 votes vote down vote up
/**
 * @param surface The surface to set.
 * @throws ExoPlaybackException
 */
private void setSurface(Surface surface) throws ExoPlaybackException {
  if (this.surface == surface) {
    return;
  }
  this.surface = surface;
  this.reportedDrawnToSurface = false;
  int state = getState();
  if (state == TrackRenderer.STATE_ENABLED || state == TrackRenderer.STATE_STARTED) {
    releaseCodec();
    maybeInitCodec();
  }
}
 
Example 28
Project: ZxingForAndroid   File: CameraManager.java   View source code 5 votes vote down vote up
private int calculateDisplayRotation() {
    // http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
    int rotation = displayConfiguration.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (cameraInfo.orientation + degrees) % 360;
        result = (360 - result) % 360;  // compensate the mirror
    } else {  // back-facing
        result = (cameraInfo.orientation - degrees + 360) % 360;
    }
    Log.i(TAG, "Camera Display Orientation: " + result);
    return result;
}
 
Example 29
Project: CameraFragment   File: Utils.java   View source code 5 votes vote down vote up
public static int getDeviceDefaultOrientation(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Configuration config = context.getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
            config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
            config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return Configuration.ORIENTATION_LANDSCAPE;
    } else {
        return Configuration.ORIENTATION_PORTRAIT;
    }
}
 
Example 30
Project: mpeg-encoder   File: InputSurfaceAndroidTest.java   View source code 5 votes vote down vote up
/** Common "before" functionality. */
@Before
public final void setUp() throws Exception {
    mEglDisplay = GLTools.newDisplay();

    final EGLConfig eglConfig = GLTools.newConfig(mEglDisplay, true);
    mEglContext = GLTools.newContext(mEglDisplay, eglConfig);
    mEglSurface = GLTools.newSurface(mEglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE);
    GLTools.makeCurrent(mEglDisplay, mEglSurface, mEglContext);

    mTexture = GLTools.newTexture(TEXTURE_LEVEL);
    mSurfaceTexture = new SurfaceTexture(mTexture, true);
    mSurface = new Surface(mSurfaceTexture);
}
 
Example 31
Project: OkayCamera-Android   File: OkCaptureRequestBuilder.java   View source code 5 votes vote down vote up
/**
 * Add a surface to the list of targets for this request,
 * The Surface added must be one of the surfaces included in the most recent call to createCaptureSession(List,
 * CameraCaptureSession.StateCallback, Handler), when the request is given to the camera device.
 * @param outputTarget Surface to use as an output target for this request
 * @throws ObjectNotInitializedException You should call init() before call this method otherwise
 * it will throw a ObjectNotInitializedException
 * @see CaptureRequest.Builder#addTarget(Surface)
 */
@Deprecated
public OkCaptureRequestBuilder addTarget(@NonNull Surface outputTarget)
        throws ObjectNotInitializedException {
    if (mBuilder != null) {
        mBuilder.addTarget(outputTarget);
    } else {
        throw genException();
    }
    return this;
}
 
Example 32
Project: polling-station-app   File: CameraFragment.java   View source code 5 votes vote down vote up
/**
 * Extract a bitmap from the textureview of this fragment.
 * @return
 */
public Bitmap extractBitmap() {
    try {
        Bitmap bitmap = mTextureView.getBitmap();
        int rotate = Surface.ROTATION_0;
        switch (getActivity().getWindowManager().getDefaultDisplay().getRotation()) {
            case Surface.ROTATION_0:
                rotate = 0;
                break;
            case Surface.ROTATION_90:
                rotate = 270;
                break;
            case Surface.ROTATION_180:
                rotate = 180;
                break;
            case Surface.ROTATION_270:
                rotate = 90;
                break;
        }
        if (rotate != Surface.ROTATION_0) {
            bitmap = CameraFragmentUtil.rotateBitmap(bitmap, rotate);
        }
        Bitmap croppedBitmap = CameraFragmentUtil.cropBitmap(bitmap, scanSegment);

        return CameraFragmentUtil.getResizedBitmap(croppedBitmap, croppedBitmap.getWidth(), croppedBitmap.getHeight());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}
 
Example 33
Project: ZxingScan   File: CameraConfigurationManager.java   View source code 5 votes vote down vote up
public int getDisplayOrientation() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int rotation = display.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;
    } else {
        result = (info.orientation - degrees + 360) % 360;
    }
    return result;
}
 
Example 34
Project: OkayCamera-Android   File: OkCaptureRequestBuilder.java   View source code 5 votes vote down vote up
public OkCaptureRequestBuilder 	removeTarget(@NonNull Surface outputTarget)
        throws ObjectNotInitializedException {
    if (mBuilder != null) {
        mBuilder.removeTarget(outputTarget);
    } else {
        throw genException();
    }
    return this;
}
 
Example 35
Project: NSMPlayer-Android   File: TextureRenderView.java   View source code 5 votes vote down vote up
@Nullable
@Override
public Surface openSurface() {
    if (mSurfaceTexture == null)
        return null;
    return new Surface(mSurfaceTexture);
}
 
Example 36
Project: Camera2Vision   File: CameraSource.java   View source code 5 votes vote down vote up
/**
 * Calculates the correct rotation for the given camera id and sets the rotation in the
 * parameters.  It also sets the camera's display orientation and rotation.
 *
 * @param parameters the camera parameters for which to set the rotation
 * @param cameraId   the camera id to set rotation based on
 */
private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) {
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int degrees = 0;
    switch (windowManager.getDefaultDisplay().getRotation()) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
        default:
            Log.e(TAG, "Bad rotation value");
    }

    CameraInfo cameraInfo = new CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);

    int angle;
    int displayAngle;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        angle = (cameraInfo.orientation + degrees) % 360;
        displayAngle = (360 - angle) % 360; // compensate for it being mirrored
    } else {  // back-facing
        angle = (cameraInfo.orientation - degrees + 360) % 360;
        displayAngle = angle;
    }

    // This corresponds to the rotation constants in {@link Frame}.
    mRotation = angle / 90;

    camera.setDisplayOrientation(displayAngle);
    parameters.setRotation(angle);
}
 
Example 37
Project: aos-MediaLib   File: AvosMediaPlayer.java   View source code 5 votes vote down vote up
public void setDisplay(SurfaceHolder sh) {
    mSurfaceHolder = sh;
    Surface surface;
    if (sh != null) {
        surface = sh.getSurface();
    } else {
        surface = null;
    }
    setVideoSurface(surface);
    updateSurfaceScreenOn();
}
 
Example 38
Project: Exoplayer2Radio   File: SimpleExoPlayer.java   View source code 5 votes vote down vote up
@Override
public void onRenderedFirstFrame(Surface surface) {
  if (videoListener != null && SimpleExoPlayer.this.surface == surface) {
    videoListener.onRenderedFirstFrame();
  }
  if (videoDebugListener != null) {
    videoDebugListener.onRenderedFirstFrame(surface);
  }
}
 
Example 39
Project: xbot_head   File: FaceOverlayView.java   View source code 5 votes vote down vote up
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mFaces != null && mFaces.length > 0) {

            float scaleX = (float) getWidth() / (float) previewWidth;
            float scaleY = (float) getHeight() / (float) previewHeight;
            switch (mDisplayOrientation) {
                case Surface.ROTATION_90:
                case Surface.ROTATION_270:
                    scaleX = (float) getWidth() / (float) previewHeight;
                    scaleY = (float) getHeight() / (float) previewWidth;
                    break;
            }

            canvas.save();
            canvas.rotate(-mOrientation);

            for (FaceResult face : mFaces) {
                PointF mid = new PointF();
                face.getMidPoint(mid);
                if (mid.x != 0.0f && mid.y != 0.0f) {
                    float eyesDis = face.eyesDistance();
                    RectF rectF = ImageUtils.getDrawFaceRectF(mid,eyesDis,scaleX,scaleY);

                    canvas.drawRect(rectF, mPaint);
//                    canvas.drawText("ID " + face.getId(), rectF.left, rectF.bottom + mTextPaint.getTextSize(), mTextPaint);
//                    canvas.drawText("Confidence " + face.getConfidence(), rectF.left, rectF.bottom + mTextPaint.getTextSize() * 2, mTextPaint);
//                    canvas.drawText("EyesDistance " + face.eyesDistance(), rectF.left, rectF.bottom + mTextPaint.getTextSize() * 3, mTextPaint);
                }
            }
            canvas.restore();
        }



//        DecimalFormat df2 = new DecimalFormat(".##");
//        canvas.drawText("Detected_Frame/s: " + df2.format(fps) + " @ " + previewWidth + "x" + previewHeight, mTextPaint.getTextSize(), mTextPaint.getTextSize(), mTextPaint);
    }
 
Example 40
Project: Hitalk   File: CameraConfigurationManager.java   View source code 5 votes vote down vote up
public int getDisplayOrientation() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int rotation = display.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;
    } else {
        result = (info.orientation - degrees + 360) % 360;
    }
    return result;
}